diff --git a/.gitignore b/.gitignore index ad3f13349..d7a4eefa5 100644 --- a/.gitignore +++ b/.gitignore @@ -11,4 +11,5 @@ profile.coverprofile /var /TODO /gin-bin -/.vscode \ No newline at end of file +/.vscode +/federation/etc/.env* diff --git a/federation/README.adoc b/federation/README.adoc index 14c8941b4..d59c2eb51 100644 --- a/federation/README.adoc +++ b/federation/README.adoc @@ -1,3 +1,31 @@ +== Development setup for origin and destination nodes + +Add the appropriate .env files +[source,bash] +---- +$ cp .env federation/etc/{.env.orig,.env.dest} +---- + +Change the DB_DSN in each of the files +---- +.env.orig: DB_DSN=corteza:rootcorteza@tcp(db_origin:3306)/corteza?collation=utf8mb4_general_ci +.env.dest: DB_DSN=corteza:rootcorteza@tcp(db_destination:3306)/corteza?collation=utf8mb4_general_ci +---- + +Run the nodes +[source,bash] +---- +$ docker-compose -f federation/etc/docker-compose.yml up -d node_origin +$ docker-compose -f federation/etc/docker-compose.yml up -d node_destination +---- + +Add testing migrations +[source,bash] +---- +$ docker-compose -f federation/etc/docker-compose.yml run db_origin mysql -u corteza -prootcorteza corteza -h localhost --port 3306 < federation/migration_federation_origin.sql +$ docker-compose -f federation/etc/docker-compose.yml run db_destination mysql -u corteza -prootcorteza corteza -h localhost --port 3307 < federation/migration_federation_destination.sql +---- + == Setup db (postgres) Add db dsn to .env @@ -12,13 +40,6 @@ Start the postgres db $ docker-compose up -db pg ---- -Add testing migrations -[source,bash] ----- -$ docker exec -i corteza-server_pg_1 psql -U docker corteza < federation/migration_federation_origin.sql -$ docker exec -i corteza-server_pg_1 psql -U docker corteza < federation/migration_federation_destination.sql ----- - == Status === Node pairing diff --git a/federation/etc/docker-compose.yml b/federation/etc/docker-compose.yml new file mode 100644 index 000000000..92993e84b --- /dev/null +++ b/federation/etc/docker-compose.yml @@ -0,0 +1,57 @@ +version: "3" +services: + db_origin: + image: percona:8.0 + container_name: db_origin + restart: on-failure + environment: + MYSQL_DATABASE: corteza + MYSQL_USER: corteza + MYSQL_PASSWORD: rootcorteza + MYSQL_ROOT_PASSWORD: rootcorteza + volumes: + - "../../data/db_origin:/var/lib/mysql" + ports: + - 3306:3306 + + db_destination: + image: percona:8.0 + container_name: db_destination + restart: on-failure + environment: + MYSQL_DATABASE: corteza + MYSQL_USER: corteza + MYSQL_PASSWORD: rootcorteza + MYSQL_ROOT_PASSWORD: rootcorteza + volumes: + - "../../data/db_destination:/var/lib/mysql" + ports: + - 3307:3306 + + node_origin: + image: golang + container_name: node_origin + entrypoint: [ make, watch ] + depends_on: [ db_origin ] + volumes: + - "../../:/app" + - "./.env.orig:/app/.env" + working_dir: /app + restart: on-failure + ports: + - 8084:8084 + + node_destination: + image: golang + container_name: node_destination + entrypoint: [ make, watch ] + depends_on: [ db_destination ] + volumes: + - "../../:/app" + - "./.env.dest:/app/.env" + working_dir: /app + restart: on-failure + ports: + - 8085:8084 + + diff --git a/federation/migration_federation_destination.sql b/federation/migration_federation_destination.sql index 764e965c8..4a0e1c736 100644 --- a/federation/migration_federation_destination.sql +++ b/federation/migration_federation_destination.sql @@ -43,9 +43,14 @@ CREATE TABLE IF NOT EXISTS federation_node PRIMARY KEY(id) ); +TRUNCATE TABLE federation_node; +TRUNCATE TABLE federation_module_shared; +TRUNCATE TABLE federation_module_exposed; +TRUNCATE TABLE federation_module_mapping; + INSERT INTO federation_node values ('276342359342989555', 'Node Origin (somewhere else)', 'paired', 'synced', now(), 'synced', now()); INSERT INTO federation_module_shared (id, handle, name, rel_node, xref_module, fields) VALUES -(206342359342988000, 'Pricebook_on_origin_somewhere_else', 'Pricebook on some other origin (somewhere else)', 276342359342989555, 196342359342989000, NULL) +(206342359342988000, 'Pricebook_on_origin_somewhere_else', 'Pricebook on some other origin (somewhere else)', 276342359342989555, 196342359342989000, '[]') ; diff --git a/federation/migration_federation_origin.sql b/federation/migration_federation_origin.sql index eb6f467e1..1168b922c 100644 --- a/federation/migration_federation_origin.sql +++ b/federation/migration_federation_origin.sql @@ -43,14 +43,19 @@ CREATE TABLE IF NOT EXISTS federation_node PRIMARY KEY(id) ); +TRUNCATE TABLE federation_node; +TRUNCATE TABLE federation_module_shared; +TRUNCATE TABLE federation_module_exposed; +TRUNCATE TABLE federation_module_mapping; + INSERT INTO federation_node values ('276342359342989444', 'Node Destination (somewhere else)', 'paired', 'synced', now(), 'synced', now()); INSERT INTO federation_module_exposed (id, rel_node, rel_compose_module, fields) VALUES -(196342359342989000, 276342359342989444, 196342359342989413, NULL) +(196342359342989000, 276342359342989444, 196342359342989413, '[]') ; INSERT INTO federation_module_shared (id, handle, name, rel_node, xref_module, fields) VALUES -(196342359342988000, 'Pricebook_on_origin_somewhere_else', 'Pricebook on some other origin (somewhere else)', 276342359342989444, 123456789012345678, NULL) +(196342359342988000, 'Pricebook_on_origin_somewhere_else', 'Pricebook on some other origin (somewhere else)', 276342359342989444, 123456789012345678, '[]') ;