From 5499d2274d7b1ba884d9b4e9c443477e1dcf9eb1 Mon Sep 17 00:00:00 2001 From: Peter Grlica Date: Fri, 18 Sep 2020 14:40:20 +0200 Subject: [PATCH] Added development readme, dev docker compose, testing db migrations --- docker-compose.yml | 24 ++++++ federation/README.adoc | 86 +++++++++++++++++++ .../migration_federation_destination.sql | 51 +++++++++++ federation/migration_federation_origin.sql | 56 ++++++++++++ 4 files changed, 217 insertions(+) create mode 100644 docker-compose.yml create mode 100644 federation/README.adoc create mode 100644 federation/migration_federation_destination.sql create mode 100644 federation/migration_federation_origin.sql diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 000000000..c412868d7 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,24 @@ +version: "3" +services: + pg: + image: postgres:12.4 + environment: + - POSTGRES_PASSWORD=docker + - POSTGRES_USER=docker + ports: + - 5432:5432 + volumes: + - ./data/pg:/var/lib/postgresql/data + db: + image: percona:8.0 + restart: on-failure + environment: + # To be picked up by percona image when creating the database + # Must match with DB_DSN settings inside .env + MYSQL_DATABASE: corteza + MYSQL_USER: corteza + MYSQL_PASSWORD: rootcorteza + MYSQL_ROOT_PASSWORD: rootcorteza + volumes: [ "./data/db:/var/lib/mysql" ] # use local fs + ports: + - 3306:3306 diff --git a/federation/README.adoc b/federation/README.adoc new file mode 100644 index 000000000..1a13a15c8 --- /dev/null +++ b/federation/README.adoc @@ -0,0 +1,86 @@ +== Setup db (postgres) + +Add db dsn to .env +[source,bash] +---- +DB_DSN=postgres+debug://docker:docker@localhost:5432/corteza?sslmode=disable +---- + +Start the postgres db +[source,bash] +---- +$ 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 + +=== Structure sync + +.List of endpoints +* [x] Show exposed module +* [x] Remove exposed module +* [x] Shared module details +* [x] List of shared/exposed modules +* [ ] Add module as exposed (with mappings) +* [ ] Add mappings to module +* [ ] Show module mappings +* [ ] Update fields on exposed module + + +Show exposed module:: +[source,bash] +---- +$ curl -X GET "$BASE_URL/federation/nodes/$NODE_ID/modules/$MODULE_ID/exposed" +---- + +Remove exposed module:: +[source,bash] +---- +$ curl -X DELETE "$BASE_URL/federation/nodes/$NODE_ID/modules/$MODULE_ID/exposed" +---- + +Shared module details:: +[source,bash] +---- +$ curl -X GET "$BASE_URL/federation/nodes/$NODE_ID/modules/$MODULE_ID/shared" +---- + +List of shared/exposed modules:: +[source,bash] +---- +$ curl -X GET "$BASE_URL/federation/nodes/$NODE_ID/modules?exposed" +$ curl -X GET "$BASE_URL/federation/nodes/$NODE_ID/modules?shared" +---- + +Add module as exposed (with mappings):: +[source,bash] +---- +curl -X PUT "$BASE_URL/federation/nodes/$NODE_ID/modules/0/exposed" +---- + +Add mappings to module:: +[source,bash] +---- +curl -X PUT "$BASE_URL/federation/nodes/$NODE_ID/modules/$MODULE_ID/mapped" +---- + +Show module mappings:: +[source,bash] +---- +curl -X GET "$BASE_URL/federation/nodes/$NODE_ID/modules/$MODULE_ID/mapped" +---- + +Update fields on exposed module:: +[source,bash] +---- +curl -X PUT "$BASE_URL/federation/nodes/$NODE_ID/modules/$MODULE_ID/exposed" +---- diff --git a/federation/migration_federation_destination.sql b/federation/migration_federation_destination.sql new file mode 100644 index 000000000..33b857bfb --- /dev/null +++ b/federation/migration_federation_destination.sql @@ -0,0 +1,51 @@ +-- Pricebook module + +-- id | rel_namespace | handle | name | meta | created_at | updated_at | deleted_at +-- --------------------+--------------------+-----------+-----------+------+-------------------------------+------------------------------+------------ +-- 196342359342989413 | 196342358990667877 | Pricebook | Pricebook | {} | 2020-09-16 12:06:05.830318+00 | 2020-09-16 12:06:15.24715+00 | + +CREATE TABLE IF NOT EXISTS federation_module_shared +( + id BIGINT NOT NULL, + handle varchar(200), + name varchar(64), + rel_node BIGINT, + xref_module BIGINT, + fields jsonb, + PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS federation_module_exposed +( + id BIGINT NOT NULL, + rel_node BIGINT, + rel_compose_module BIGINT, + fields jsonb, + PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS federation_module_mapping +( + federation_module_id BIGINT, + compose_module_id BIGINT, + field_mapping jsonb +); + +CREATE TABLE IF NOT EXISTS federation_node +( + id BIGINT NOT NULL, + name varchar(256), + status varchar(64), + structure_status varchar(64), + structure_synced_at varchar(64), + data_status varchar(64), + data_synced_at varchar(64), + PRIMARY KEY(id) +); + +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) +; diff --git a/federation/migration_federation_origin.sql b/federation/migration_federation_origin.sql new file mode 100644 index 000000000..0db993bc7 --- /dev/null +++ b/federation/migration_federation_origin.sql @@ -0,0 +1,56 @@ +-- Pricebook module + +-- id | rel_namespace | handle | name | meta | created_at | updated_at | deleted_at +-- --------------------+--------------------+-----------+-----------+------+-------------------------------+------------------------------+------------ +-- 196342359342989413 | 196342358990667877 | Pricebook | Pricebook | {} | 2020-09-16 12:06:05.830318+00 | 2020-09-16 12:06:15.24715+00 | + +CREATE TABLE IF NOT EXISTS federation_module_shared +( + id BIGINT NOT NULL, + handle varchar(200), + name varchar(64), + rel_node BIGINT, + xref_module BIGINT, + fields jsonb, + PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS federation_module_exposed +( + id BIGINT NOT NULL, + rel_node BIGINT, + rel_compose_module BIGINT, + fields jsonb, + PRIMARY KEY (id) +); + +CREATE TABLE IF NOT EXISTS federation_module_mapping +( + federation_module_id BIGINT, + compose_module_id BIGINT, + field_mapping jsonb +); + +CREATE TABLE IF NOT EXISTS federation_node +( + id BIGINT NOT NULL, + name varchar(256), + status varchar(64), + structure_status varchar(64), + structure_synced_at varchar(64), + data_status varchar(64), + data_synced_at varchar(64), + PRIMARY KEY(id) +); + +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) +; + +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) +;