Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement the Postgres integration #175

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
16 changes: 16 additions & 0 deletions db/postgres/v1.0.0-beta/001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
SET client_min_messages TO WARNING;

CREATE TABLE IF NOT EXISTS inputs (
output_reference BYTEA NOT NULL,
address TEXT NOT NULL,
value BYTEA NOT NULL,
datum_hash BYTEA,
slot_no INTEGER NOT NULL,
PRIMARY KEY (output_reference)
);

CREATE TABLE IF NOT EXISTS checkpoints (
header_hash BYTEA NOT NULL,
slot_no INTEGER NOT NULL,
PRIMARY KEY (slot_no)
);
15 changes: 15 additions & 0 deletions db/postgres/v1.0.0/001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SET client_min_messages TO WARNING;

DROP TABLE inputs;

CREATE TABLE IF NOT EXISTS inputs (
output_reference BYTEA NOT NULL,
address TEXT NOT NULL,
value BYTEA NOT NULL,
datum_hash BYTEA,
header_hash BYTEA NOT NULL,
slot_no INTEGER NOT NULL,
PRIMARY KEY (output_reference)
);

DELETE FROM checkpoints;
6 changes: 6 additions & 0 deletions db/postgres/v1.0.0/002.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SET client_min_messages TO WARNING;

CREATE TABLE IF NOT EXISTS patterns (
pattern TEXT NOT NULL,
PRIMARY KEY (pattern)
);
43 changes: 43 additions & 0 deletions db/postgres/v1.0.1/001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
DELETE FROM inputs WHERE output_reference >= '\x825820f9ed2fef27cdcf60c863ba03f27d0e38f39c5047cf73ffdf2428b48edbe8323400' AND output_reference <= '\x825820f9ed2fef27cdcf60c863ba03f27d0e38f39c5047cf73ffdf2428b48edbe8323417';
DELETE FROM inputs WHERE output_reference >= '\x8258209298f499a4c4aeba53a984cb4df0f9a93b7d158da4c2c2d12a06530841f94cd700' AND output_reference <= '\x8258209298f499a4c4aeba53a984cb4df0f9a93b7d158da4c2c2d12a06530841f94cd717';
DELETE FROM inputs WHERE output_reference >= '\x82582037ae93fc2e1193f0a801d750f84bd3448e50b60915c42017c1077ff77060f4a800' AND output_reference <= '\x82582037ae93fc2e1193f0a801d750f84bd3448e50b60915c42017c1077ff77060f4a817';
DELETE FROM inputs WHERE output_reference >= '\x82582095b2f040e566200ae41e65a6197d21090eeeeef0c15427b814a9b915158bc10100' AND output_reference <= '\x82582095b2f040e566200ae41e65a6197d21090eeeeef0c15427b814a9b915158bc10117';
DELETE FROM inputs WHERE output_reference >= '\x825820bc48b849255582c073c0e703f4b70d51aeab81d35c5de32b7d364966aa1a544900' AND output_reference <= '\x825820bc48b849255582c073c0e703f4b70d51aeab81d35c5de32b7d364966aa1a544917';
DELETE FROM inputs WHERE output_reference >= '\x825820df388c44bf8de15e6080007ea190dc1b48f62c862389d68396641a15131fe4e100' AND output_reference <= '\x825820df388c44bf8de15e6080007ea190dc1b48f62c862389d68396641a15131fe4e117';
DELETE FROM inputs WHERE output_reference >= '\x825820899e6dfa57b0bae60069dd82c449ddcaed56dd09bd4483ca6c5c61584a0b777600' AND output_reference <= '\x825820899e6dfa57b0bae60069dd82c449ddcaed56dd09bd4483ca6c5c61584a0b777617';
DELETE FROM inputs WHERE output_reference >= '\x825820b03c7a70cfcd11bac77bb9d6e5020ceeceec76b1f09d22960c79ea4b496ea53400' AND output_reference <= '\x825820b03c7a70cfcd11bac77bb9d6e5020ceeceec76b1f09d22960c79ea4b496ea53417';
DELETE FROM inputs WHERE output_reference >= '\x825820116fc11e143f6e6c685ea23f4f191d5d54df39359ecdfc7d53506f048fc713b600' AND output_reference <= '\x825820116fc11e143f6e6c685ea23f4f191d5d54df39359ecdfc7d53506f048fc713b617';
DELETE FROM inputs WHERE output_reference >= '\x82582062f7df4fce8cbe478c68f1cf4ab502a61c86c922bb10de025034177bd6ba4b0300' AND output_reference <= '\x82582062f7df4fce8cbe478c68f1cf4ab502a61c86c922bb10de025034177bd6ba4b0317';
DELETE FROM inputs WHERE output_reference >= '\x825820e7a8172232688851112f088754247ff212313a564169fa029b1fdb830a04e5b500' AND output_reference <= '\x825820e7a8172232688851112f088754247ff212313a564169fa029b1fdb830a04e5b517';
DELETE FROM inputs WHERE output_reference >= '\x82582089249ef42073233e87c98080c166d716624e1363b9e0f8b744cfcd040592998b00' AND output_reference <= '\x82582089249ef42073233e87c98080c166d716624e1363b9e0f8b744cfcd040592998b17';
DELETE FROM inputs WHERE output_reference >= '\x825820a467c4f72d1be92f1c23b675a6313b6a8c7302ae28be9d36a9f3961458e6c20700' AND output_reference <= '\x825820a467c4f72d1be92f1c23b675a6313b6a8c7302ae28be9d36a9f3961458e6c20717';
DELETE FROM inputs WHERE output_reference >= '\x82582058c8a04c8b78a99cd7337a6589489b54027fa16b918b3a45bddb78e39c65939500' AND output_reference <= '\x82582058c8a04c8b78a99cd7337a6589489b54027fa16b918b3a45bddb78e39c65939517';
DELETE FROM inputs WHERE output_reference >= '\x82582043149210cbbfbc92bc2b199bb14cb15330414e2288ac31be92a3b5a490f9abfc00' AND output_reference <= '\x82582043149210cbbfbc92bc2b199bb14cb15330414e2288ac31be92a3b5a490f9abfc17';
DELETE FROM inputs WHERE output_reference >= '\x8258208efd9d40433726a6693b6845078b97dc0c72cf381103bfec838331d8ea3475e700' AND output_reference <= '\x8258208efd9d40433726a6693b6845078b97dc0c72cf381103bfec838331d8ea3475e717';
DELETE FROM inputs WHERE output_reference >= '\x825820efd21930e7b5b49f8d907a1b6ca5aeaa560334e762a05df9182ba4f1d1f6d43000' AND output_reference <= '\x825820efd21930e7b5b49f8d907a1b6ca5aeaa560334e762a05df9182ba4f1d1f6d43017';
DELETE FROM inputs WHERE output_reference >= '\x825820e43f8adc738f3352ebd02a673ba9a69fb7ecf4612843166dd9d8081bbc29503b00' AND output_reference <= '\x825820e43f8adc738f3352ebd02a673ba9a69fb7ecf4612843166dd9d8081bbc29503b17';
DELETE FROM inputs WHERE output_reference >= '\x825820eddd01ce4b025fe8c5eb9b69b45f551d34bc08649da876a89e95414e2ea9149700' AND output_reference <= '\x825820eddd01ce4b025fe8c5eb9b69b45f551d34bc08649da876a89e95414e2ea9149717';
DELETE FROM inputs WHERE output_reference >= '\x825820a694dc595e1bfd0ca703374f89fdaa18a9faa5de8790ff724040df5d45e7af0500' AND output_reference <= '\x825820a694dc595e1bfd0ca703374f89fdaa18a9faa5de8790ff724040df5d45e7af0517';
DELETE FROM inputs WHERE output_reference >= '\x8258205c19cd2d962c22b51e7de12626f577229fc7caa9c517920f034002b69ed897db00' AND output_reference <= '\x8258205c19cd2d962c22b51e7de12626f577229fc7caa9c517920f034002b69ed897db17';
DELETE FROM inputs WHERE output_reference >= '\x825820d2f9a485d35a7ac67d2a9a69155d7ecd5713c960540799e58a615ffe5454868f00' AND output_reference <= '\x825820d2f9a485d35a7ac67d2a9a69155d7ecd5713c960540799e58a615ffe5454868f17';
DELETE FROM inputs WHERE output_reference >= '\x825820f94d6cd0891629c71c4e82c71e01263e332e5ef8828b2bd247d6dd1dddc2ce4a00' AND output_reference <= '\x825820f94d6cd0891629c71c4e82c71e01263e332e5ef8828b2bd247d6dd1dddc2ce4a17';
DELETE FROM inputs WHERE output_reference >= '\x825820ca08eb39a83cd68d6ff11205eda33cbcf62bc7ad71d9c2aae5cdab1ececa5d8100' AND output_reference <= '\x825820ca08eb39a83cd68d6ff11205eda33cbcf62bc7ad71d9c2aae5cdab1ececa5d8117';
DELETE FROM inputs WHERE output_reference >= '\x825820afaba424e5c986f396bfa6d561fe0b7c98fa61408ffc3de3cae61e81c5bb90b200' AND output_reference <= '\x825820afaba424e5c986f396bfa6d561fe0b7c98fa61408ffc3de3cae61e81c5bb90b217';
DELETE FROM inputs WHERE output_reference >= '\x825820ab82002b00646a154c046d4c79fd5c14d6de0c833fe01206007d5ffe90fa3fff00' AND output_reference <= '\x825820ab82002b00646a154c046d4c79fd5c14d6de0c833fe01206007d5ffe90fa3fff17';
DELETE FROM inputs WHERE output_reference >= '\x8258207d590872f41c60b9be0870f5c0fb1859d7a033d4923ebd3fc08801434fb1e71600' AND output_reference <= '\x8258207d590872f41c60b9be0870f5c0fb1859d7a033d4923ebd3fc08801434fb1e71617';
DELETE FROM inputs WHERE output_reference >= '\x8258209858125ad4041fc3b914617f6c51db15df2fff115a45155a5cc65908b46ce2ac00' AND output_reference <= '\x8258209858125ad4041fc3b914617f6c51db15df2fff115a45155a5cc65908b46ce2ac17';
DELETE FROM inputs WHERE output_reference >= '\x8258202cdfaf95363604f0efb4993be35f03ccd2146863b151b49affea9d3af3344c4800' AND output_reference <= '\x8258202cdfaf95363604f0efb4993be35f03ccd2146863b151b49affea9d3af3344c4817';
DELETE FROM inputs WHERE output_reference >= '\x825820a08fe6c359c03433a29f01787ec951e8626d827cd99241c156250a7340ba321400' AND output_reference <= '\x825820a08fe6c359c03433a29f01787ec951e8626d827cd99241c156250a7340ba321417';
DELETE FROM inputs WHERE output_reference >= '\x8258208cb25305efc0e4f897d9c421039871803786617bec23467008c42ff646fd62fa00' AND output_reference <= '\x8258208cb25305efc0e4f897d9c421039871803786617bec23467008c42ff646fd62fa17';
DELETE FROM inputs WHERE output_reference >= '\x825820bfab189d9addbab5030a0f1820470ded8e90621f39e9612563393526b690ff3e00' AND output_reference <= '\x825820bfab189d9addbab5030a0f1820470ded8e90621f39e9612563393526b690ff3e17';
DELETE FROM inputs WHERE output_reference >= '\x82582007c3d8abc5b49ac8d844e50735bdc535250d29e79d159ad22c8308048e3bc6f200' AND output_reference <= '\x82582007c3d8abc5b49ac8d844e50735bdc535250d29e79d159ad22c8308048e3bc6f217';
DELETE FROM inputs WHERE output_reference >= '\x8258203b1f218b82459345213d7cb2d9700b3f4087c6433051394edcb8f7d5fa9f994f00' AND output_reference <= '\x8258203b1f218b82459345213d7cb2d9700b3f4087c6433051394edcb8f7d5fa9f994f17';
DELETE FROM inputs WHERE output_reference >= '\x825820860e932bec46e05a0212bd36db55152b8468378140a61f22127851f134dcbde400' AND output_reference <= '\x825820860e932bec46e05a0212bd36db55152b8468378140a61f22127851f134dcbde417';
DELETE FROM inputs WHERE output_reference >= '\x8258205f81ef623e69122582f2a285a04092fe2a92afef42680e6a9049e8a8339857dc00' AND output_reference <= '\x8258205f81ef623e69122582f2a285a04092fe2a92afef42680e6a9049e8a8339857dc17';
DELETE FROM inputs WHERE output_reference >= '\x8258203d1c3c7ae3db0bd1c4d310e953ca0f319b7adf58b5628b915e0f01948ec77f1d00' AND output_reference <= '\x8258203d1c3c7ae3db0bd1c4d310e953ca0f319b7adf58b5628b915e0f01948ec77f1d17';
DELETE FROM inputs WHERE output_reference >= '\x82582041ae901251f5a3313b2e7fc1d121201c239df3f2b30c0097bd0cc1cb47bc61ae00' AND output_reference <= '\x82582041ae901251f5a3313b2e7fc1d121201c239df3f2b30c0097bd0cc1cb47bc61ae17';
DELETE FROM inputs WHERE output_reference >= '\x8258208500961c30306118533ae18d3ef99baf8bbd2594cfac26cb012495070a5634eb00' AND output_reference <= '\x8258208500961c30306118533ae18d3ef99baf8bbd2594cfac26cb012495070a5634eb17';
DELETE FROM inputs WHERE output_reference >= '\x82582098664faaddf6804e7478bb2d77f5c9d9aea3516d050a73db4c6b47b1e700424c00' AND output_reference <= '\x82582098664faaddf6804e7478bb2d77f5c9d9aea3516d050a73db4c6b47b1e700424c17';
DELETE FROM inputs WHERE output_reference >= '\x825820e2dd9967b59e6a8a64afdf99c0b3519b5221d010515d6c68396e4ca00625733c00' AND output_reference <= '\x825820e2dd9967b59e6a8a64afdf99c0b3519b5221d010515d6c68396e4ca00625733c17';
DELETE FROM inputs WHERE output_reference >= '\x825820c8db1cd16ed19f92917fa253615ade21e442bda56809f97744a1b3dfadea41f300' AND output_reference <= '\x825820c8db1cd16ed19f92917fa253615ade21e442bda56809f97744a1b3dfadea41f317';
DELETE FROM inputs WHERE output_reference >= '\x825820787428e48b09bb8bcca74c11ddec7f2ad8d709b72850ef9a6904d81a3552d30700' AND output_reference <= '\x825820787428e48b09bb8bcca74c11ddec7f2ad8d709b72850ef9a6904d81a3552d30717';
28 changes: 28 additions & 0 deletions db/postgres/v2.0.0-beta/001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
SET client_min_messages TO WARNING;

DROP TABLE inputs;

CREATE TABLE IF NOT EXISTS inputs (
output_reference BYTEA NOT NULL,
address TEXT NOT NULL,
value BYTEA NOT NULL,
datum_hash BYTEA,
script_hash BYTEA,
created_at INTEGER NOT NULL,
spent_at INTEGER,
PRIMARY KEY (output_reference)
);

DELETE FROM checkpoints;

CREATE TABLE IF NOT EXISTS binary_data (
binary_data_hash BYTEA NOT NULL,
binary_data BYTEA NOT NULL,
PRIMARY KEY (binary_data_hash)
);

CREATE TABLE IF NOT EXISTS scripts (
script_hash BYTEA NOT NULL,
script BYTEA NOT NULL,
PRIMARY KEY (script_hash)
);
6 changes: 6 additions & 0 deletions db/postgres/v2.1.0/001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
SET client_min_messages TO WARNING;

DELETE FROM inputs;
DELETE FROM checkpoints;
DELETE FROM binary_data;
DELETE FROM scripts;
3 changes: 3 additions & 0 deletions db/postgres/v2.1.0/002.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
SET client_min_messages TO WARNING;

ALTER TABLE inputs ADD COLUMN payment_credential TEXT GENERATED ALWAYS AS (substr(address, -56)) STORED;
19 changes: 19 additions & 0 deletions db/postgres/v2.1.0/003.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
SET client_min_messages TO WARNING;

ALTER TABLE inputs RENAME COLUMN output_reference TO ext_output_reference;

ALTER TABLE inputs ADD COLUMN output_reference BYTEA NOT NULL GENERATED ALWAYS AS (substr(ext_output_reference, 1, 34)) STORED;
ALTER TABLE inputs ADD COLUMN output_index BYTEA NOT NULL GENERATED ALWAYS AS (substr(ext_output_reference, -4, 2)) STORED;
ALTER TABLE inputs ADD COLUMN transaction_index BYTEA NOT NULL GENERATED ALWAYS AS (substr(ext_output_reference, -2)) STORED;

CREATE UNIQUE INDEX IF NOT EXISTS inputsByOutputReference ON inputs(output_reference);

CREATE TABLE IF NOT EXISTS policies (
output_reference BYTEA NOT NULL,
policy_id BYTEA NOT NULL,
PRIMARY KEY (output_reference, policy_id),
CONSTRAINT fk_policies_inputs
FOREIGN KEY (output_reference)
REFERENCES inputs(output_reference)
ON DELETE CASCADE
);
14 changes: 14 additions & 0 deletions db/postgres/v2.2.0/001.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
SET client_min_messages TO WARNING;

DELETE FROM checkpoints;
DELETE FROM policies;
DELETE FROM inputs;

DROP INDEX IF EXISTS inputsByCreatedAt;
DROP INDEX IF EXISTS inputsBySpentAt;
DROP INDEX IF EXISTS inputsByDatumHash;
DROP INDEX IF EXISTS inputsByAddress;
DROP INDEX IF EXISTS inputsByPaymentCredential;

ALTER TABLE inputs RENAME COLUMN datum_hash TO datum_info;
ALTER TABLE inputs ADD COLUMN datum_hash BYTEA GENERATED ALWAYS AS (substr(datum_info, 2)) STORED;
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion db/v2.0.0-beta/001.sql → db/sqlite/v2.0.0-beta/001.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ DROP TABLE inputs;

CREATE TABLE IF NOT EXISTS inputs (
output_reference BLOB NOT NULL,
address TEXT COLLATE NOCASE NOT NULL,
address TEXT NOT NULL,
value BLOB NOT NULL,
datum_hash BLOB,
script_hash BLOB,
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading
Loading