From 1124b930f9af19095b246bb2de9ae6336f7d97ca Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Mon, 3 Jan 2022 12:45:54 -0500 Subject: [PATCH 1/2] Add postgres migrations for onchain-logic Signed-off-by: Nicko Guyer --- .../postgres/000049_create_ffi_table.down.sql | 3 +++ .../postgres/000049_create_ffi_table.up.sql | 14 ++++++++++++++ .../000050_create_ffi_methods_table.down.sql | 3 +++ .../000050_create_ffi_methods_table.up.sql | 15 +++++++++++++++ .../000051_create_ffi_events_table.down.sql | 3 +++ .../000051_create_ffi_events_table.up.sql | 14 ++++++++++++++ .../000052_create_contractapis_table.down.sql | 3 +++ .../000052_create_contractapis_table.up.sql | 13 +++++++++++++ ...3_create_contractsubscriptions_table.down.sql} | 2 +- ...053_create_contractsubscriptions_table.up.sql} | 4 ++-- ...> 000054_create_contractevents_table.down.sql} | 2 +- ... => 000054_create_contractevents_table.up.sql} | 6 +++--- 12 files changed, 75 insertions(+), 7 deletions(-) create mode 100644 db/migrations/postgres/000049_create_ffi_table.down.sql create mode 100644 db/migrations/postgres/000049_create_ffi_table.up.sql create mode 100644 db/migrations/postgres/000050_create_ffi_methods_table.down.sql create mode 100644 db/migrations/postgres/000050_create_ffi_methods_table.up.sql create mode 100644 db/migrations/postgres/000051_create_ffi_events_table.down.sql create mode 100644 db/migrations/postgres/000051_create_ffi_events_table.up.sql create mode 100644 db/migrations/postgres/000052_create_contractapis_table.down.sql create mode 100644 db/migrations/postgres/000052_create_contractapis_table.up.sql rename db/migrations/postgres/{000052_create_contractsubscriptions_table.down.sql => 000053_create_contractsubscriptions_table.down.sql} (86%) rename db/migrations/postgres/{000052_create_contractsubscriptions_table.up.sql => 000053_create_contractsubscriptions_table.up.sql} (91%) rename db/migrations/postgres/{000053_create_contractevents_table.down.sql => 000054_create_contractevents_table.down.sql} (84%) rename db/migrations/postgres/{000053_create_contractevents_table.up.sql => 000054_create_contractevents_table.up.sql} (70%) diff --git a/db/migrations/postgres/000049_create_ffi_table.down.sql b/db/migrations/postgres/000049_create_ffi_table.down.sql new file mode 100644 index 0000000000..d4006ad832 --- /dev/null +++ b/db/migrations/postgres/000049_create_ffi_table.down.sql @@ -0,0 +1,3 @@ +BEGIN; +DROP TABLE IF EXISTS ffi; +COMMIT; \ No newline at end of file diff --git a/db/migrations/postgres/000049_create_ffi_table.up.sql b/db/migrations/postgres/000049_create_ffi_table.up.sql new file mode 100644 index 0000000000..75b2a739de --- /dev/null +++ b/db/migrations/postgres/000049_create_ffi_table.up.sql @@ -0,0 +1,14 @@ +BEGIN; +CREATE TABLE ffi ( + seq SERIAL PRIMARY KEY, + id UUID NOT NULL, + namespace VARCHAR(64) NOT NULL, + name VARCHAR(1024) NOT NULL, + version VARCHAR(64) NOT NULL, + description TEXT NOT NULL, + message_id UUID NOT NULL +); + +CREATE UNIQUE INDEX ffi_id ON ffi(id); +CREATE UNIQUE INDEX ffi_name ON ffi(namespace,name,version); +COMMIT; \ No newline at end of file diff --git a/db/migrations/postgres/000050_create_ffi_methods_table.down.sql b/db/migrations/postgres/000050_create_ffi_methods_table.down.sql new file mode 100644 index 0000000000..cb2aa14a03 --- /dev/null +++ b/db/migrations/postgres/000050_create_ffi_methods_table.down.sql @@ -0,0 +1,3 @@ +BEGIN; +DROP TABLE IF EXISTS ffimethods; +COMMIT; \ No newline at end of file diff --git a/db/migrations/postgres/000050_create_ffi_methods_table.up.sql b/db/migrations/postgres/000050_create_ffi_methods_table.up.sql new file mode 100644 index 0000000000..13f5cd646b --- /dev/null +++ b/db/migrations/postgres/000050_create_ffi_methods_table.up.sql @@ -0,0 +1,15 @@ +BEGIN; +CREATE TABLE ffimethods ( + seq SERIAL PRIMARY KEY, + id UUID NOT NULL, + interface_id UUID NOT NULL, + namespace VARCHAR(64) NOT NULL, + name VARCHAR(1024) NOT NULL, + pathname VARCHAR(1024) NOT NULL, + description TEXT NOT NULL, + params BYTEA NOT NULL, + returns BYTEA NOT NULL +); + +CREATE UNIQUE INDEX ffimethods_pathname ON ffimethods(interface_id,pathname); +COMMIT; \ No newline at end of file diff --git a/db/migrations/postgres/000051_create_ffi_events_table.down.sql b/db/migrations/postgres/000051_create_ffi_events_table.down.sql new file mode 100644 index 0000000000..14ac26181d --- /dev/null +++ b/db/migrations/postgres/000051_create_ffi_events_table.down.sql @@ -0,0 +1,3 @@ +BEGIN; +DROP TABLE IF EXISTS ffievents; +COMMIT; \ No newline at end of file diff --git a/db/migrations/postgres/000051_create_ffi_events_table.up.sql b/db/migrations/postgres/000051_create_ffi_events_table.up.sql new file mode 100644 index 0000000000..f0d1dd1328 --- /dev/null +++ b/db/migrations/postgres/000051_create_ffi_events_table.up.sql @@ -0,0 +1,14 @@ +BEGIN; +CREATE TABLE ffievents ( + seq SERIAL PRIMARY KEY, + id UUID NOT NULL, + interface_id UUID NULL, + namespace VARCHAR(64) NOT NULL, + name VARCHAR(1024) NOT NULL, + pathname VARCHAR(1024) NOT NULL, + description TEXT NOT NULL, + params BYTEA NOT NULL +); + +CREATE UNIQUE INDEX ffievents_pathname ON ffievents(interface_id,pathname); +COMMIT; \ No newline at end of file diff --git a/db/migrations/postgres/000052_create_contractapis_table.down.sql b/db/migrations/postgres/000052_create_contractapis_table.down.sql new file mode 100644 index 0000000000..28c417aa51 --- /dev/null +++ b/db/migrations/postgres/000052_create_contractapis_table.down.sql @@ -0,0 +1,3 @@ +BEGIN; +DROP TABLE IF EXISTS contractapis; +COMMIT; \ No newline at end of file diff --git a/db/migrations/postgres/000052_create_contractapis_table.up.sql b/db/migrations/postgres/000052_create_contractapis_table.up.sql new file mode 100644 index 0000000000..1153b1c5b9 --- /dev/null +++ b/db/migrations/postgres/000052_create_contractapis_table.up.sql @@ -0,0 +1,13 @@ +BEGIN; +CREATE TABLE contractapis ( + seq SERIAL PRIMARY KEY, + id UUID NOT NULL, + interface_id UUID NOT NULL, + ledger BYTEA, + location BYTEA, + name VARCHAR(64) NOT NULL, + namespace VARCHAR(64) NOT NULL +); + +CREATE UNIQUE INDEX contractapis_namespace_name ON contractapis(namespace,name); +COMMIT; \ No newline at end of file diff --git a/db/migrations/postgres/000052_create_contractsubscriptions_table.down.sql b/db/migrations/postgres/000053_create_contractsubscriptions_table.down.sql similarity index 86% rename from db/migrations/postgres/000052_create_contractsubscriptions_table.down.sql rename to db/migrations/postgres/000053_create_contractsubscriptions_table.down.sql index 5bb1803e4e..88ea7ba4ab 100644 --- a/db/migrations/postgres/000052_create_contractsubscriptions_table.down.sql +++ b/db/migrations/postgres/000053_create_contractsubscriptions_table.down.sql @@ -1,3 +1,3 @@ BEGIN; DROP TABLE IF EXISTS contractsubscriptions; -COMMIT; +COMMIT; \ No newline at end of file diff --git a/db/migrations/postgres/000052_create_contractsubscriptions_table.up.sql b/db/migrations/postgres/000053_create_contractsubscriptions_table.up.sql similarity index 91% rename from db/migrations/postgres/000052_create_contractsubscriptions_table.up.sql rename to db/migrations/postgres/000053_create_contractsubscriptions_table.up.sql index 526e307710..a17d94b376 100644 --- a/db/migrations/postgres/000052_create_contractsubscriptions_table.up.sql +++ b/db/migrations/postgres/000053_create_contractsubscriptions_table.up.sql @@ -3,7 +3,7 @@ CREATE TABLE contractsubscriptions ( seq SERIAL PRIMARY KEY, id UUID NOT NULL, interface_id UUID NULL, - event_id UUID NOT NULL, + event BYTEA NOT NULL, namespace VARCHAR(64) NOT NULL, name VARCHAR(64) NULL, protocol_id VARCHAR(1024) NOT NULL, @@ -13,4 +13,4 @@ CREATE TABLE contractsubscriptions ( CREATE UNIQUE INDEX contractsubscriptions_protocolid ON contractsubscriptions(protocol_id); CREATE UNIQUE INDEX contractsubscriptions_name ON contractsubscriptions(namespace,name); -COMMIT; +COMMIT; \ No newline at end of file diff --git a/db/migrations/postgres/000053_create_contractevents_table.down.sql b/db/migrations/postgres/000054_create_contractevents_table.down.sql similarity index 84% rename from db/migrations/postgres/000053_create_contractevents_table.down.sql rename to db/migrations/postgres/000054_create_contractevents_table.down.sql index cfaef46d18..13abc8804b 100644 --- a/db/migrations/postgres/000053_create_contractevents_table.down.sql +++ b/db/migrations/postgres/000054_create_contractevents_table.down.sql @@ -1,3 +1,3 @@ BEGIN; DROP TABLE IF EXISTS contractevents; -COMMIT; +COMMIT; \ No newline at end of file diff --git a/db/migrations/postgres/000053_create_contractevents_table.up.sql b/db/migrations/postgres/000054_create_contractevents_table.up.sql similarity index 70% rename from db/migrations/postgres/000053_create_contractevents_table.up.sql rename to db/migrations/postgres/000054_create_contractevents_table.up.sql index 1bc61b8818..b6866409be 100644 --- a/db/migrations/postgres/000053_create_contractevents_table.up.sql +++ b/db/migrations/postgres/000054_create_contractevents_table.up.sql @@ -1,12 +1,12 @@ BEGIN; CREATE TABLE contractevents ( - seq INTEGER PRIMARY KEY AUTOINCREMENT, + seq SERIAL PRIMARY KEY, id UUID NOT NULL, namespace VARCHAR(64) NOT NULL, name VARCHAR(1024) NOT NULL, subscription_id UUID NOT NULL, outputs BYTEA, info BYTEA, - created BIGINT NOT NULL + timestamp BIGINT NOT NULL ); -COMMIT; +COMMIT; \ No newline at end of file From 2c1a7dc231b1d7143a0252bc573fd9adab0d8eae Mon Sep 17 00:00:00 2001 From: Nicko Guyer Date: Fri, 7 Jan 2022 15:52:12 -0500 Subject: [PATCH 2/2] Add indexes to contractevents table Signed-off-by: Nicko Guyer --- .../postgres/000054_create_contractevents_table.up.sql | 3 +++ .../sqlite/000054_create_contractevents_table.up.sql | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/db/migrations/postgres/000054_create_contractevents_table.up.sql b/db/migrations/postgres/000054_create_contractevents_table.up.sql index b6866409be..c329a570c0 100644 --- a/db/migrations/postgres/000054_create_contractevents_table.up.sql +++ b/db/migrations/postgres/000054_create_contractevents_table.up.sql @@ -9,4 +9,7 @@ CREATE TABLE contractevents ( info BYTEA, timestamp BIGINT NOT NULL ); +CREATE UNIQUE INDEX contractevents_name ON contractevents(namespace,name); +CREATE UNIQUE INDEX contractevents_timestamp ON contractevents(timestamp); +CREATE UNIQUE INDEX contractevents_subscription_id ON contractevents(subscription_id); COMMIT; \ No newline at end of file diff --git a/db/migrations/sqlite/000054_create_contractevents_table.up.sql b/db/migrations/sqlite/000054_create_contractevents_table.up.sql index 4c3d49178b..97ead7ea56 100644 --- a/db/migrations/sqlite/000054_create_contractevents_table.up.sql +++ b/db/migrations/sqlite/000054_create_contractevents_table.up.sql @@ -8,3 +8,7 @@ CREATE TABLE contractevents ( info BYTEA, timestamp BIGINT NOT NULL ); + +CREATE UNIQUE INDEX contractevents_name ON contractevents(namespace,name); +CREATE UNIQUE INDEX contractevents_timestamp ON contractevents(timestamp); +CREATE UNIQUE INDEX contractevents_subscription_id ON contractevents(subscription_id); \ No newline at end of file