From 392a16b9e26d3aec89aabd76afa954734789ad9f Mon Sep 17 00:00:00 2001 From: Patotking12 Date: Fri, 20 Sep 2024 08:49:18 -0600 Subject: [PATCH] feat(bnsv2): added migration files for tables names_v2 and namespaces_v2 --- .../20240912154500_add_bns_v2_names_table.js | 106 +++++++++++++++ ...40912154500_add_bns_v2_namespaces_table.js | 123 ++++++++++++++++++ 2 files changed, 229 insertions(+) create mode 100644 migrations/20240912154500_add_bns_v2_names_table.js create mode 100644 migrations/20240912154500_add_bns_v2_namespaces_table.js diff --git a/migrations/20240912154500_add_bns_v2_names_table.js b/migrations/20240912154500_add_bns_v2_names_table.js new file mode 100644 index 000000000..cd312a580 --- /dev/null +++ b/migrations/20240912154500_add_bns_v2_names_table.js @@ -0,0 +1,106 @@ +/** @param { import("node-pg-migrate").MigrationBuilder } pgm */ +exports.up = pgm => { + pgm.createTable('names_v2', { + id: { + type: 'serial', + primaryKey: true, + }, + fullName: { + type: 'string', + notNull: true, + }, + name: { + type: 'string', + notNull: true, + }, + namespace_id: { + type: 'string', + notNull: true, + }, + registered_at: { + type: 'integer', + notNull: false, + }, + imported_at: { + type: 'integer', + notNull: false, + }, + hashed_salted_fqn_preorder: { + type: 'string', + notNull: false, + }, + preordered_by: { + type: 'string', + notNull: false, + }, + renewal_height: { + type: 'integer', + notNull: true, + }, + stx_burn: { + type: 'bigint', + notNull: true, + }, + owner: { + type: 'string', + notNull: true, + }, + tx_id: { + type: 'bytea', + notNull: true, + }, + tx_index: { + type: 'smallint', + notNull: true, + }, + event_index: 'integer', + status: { + type: 'string', + notNull: false, + }, + canonical: { + type: 'boolean', + notNull: true, + default: true, + }, + index_block_hash: { + type: 'bytea', + notNull: true, + }, + parent_index_block_hash: { + type: 'bytea', + notNull: true, + }, + microblock_hash: { + type: 'bytea', + notNull: true, + }, + microblock_sequence: { + type: 'integer', + notNull: true, + }, + microblock_canonical: { + type: 'boolean', + notNull: true, + }, + }); + + pgm.createIndex('names_v2', 'namespace_id'); + pgm.createIndex('names_v2', 'index_block_hash'); + pgm.createIndex('names_v2', [ + { name: 'registered_at', sort: 'DESC' }, + { name: 'microblock_sequence', sort: 'DESC' }, + { name: 'tx_index', sort: 'DESC' }, + { name: 'event_index', sort: 'DESC' }, + ]); + pgm.addConstraint( + 'names_v2', + 'unique_name_v2_tx_id_index_block_hash_microblock_hash_event_index', + 'UNIQUE(fullName, tx_id, index_block_hash, microblock_hash, event_index)' + ); + pgm.addConstraint('names_v2', 'unique_fullname', 'UNIQUE(fullName)'); +}; + +exports.down = pgm => { + pgm.dropTable('names_v2'); +}; diff --git a/migrations/20240912154500_add_bns_v2_namespaces_table.js b/migrations/20240912154500_add_bns_v2_namespaces_table.js new file mode 100644 index 000000000..e67f356c7 --- /dev/null +++ b/migrations/20240912154500_add_bns_v2_namespaces_table.js @@ -0,0 +1,123 @@ +/** @param { import("node-pg-migrate").MigrationBuilder } pgm */ +exports.up = pgm => { + pgm.createTable('namespaces_v2', { + id: { + type: 'serial', + primaryKey: true, + }, + namespace_id: { + type: 'string', + notNull: true, + }, + namespace_manager: { + type: 'string', + notNull: false, + }, + manager_transferable: { + type: 'boolean', + notNull: true, + }, + manager_frozen: { + type: 'boolean', + notNull: true, + }, + namespace_import: { + type: 'string', + notNull: true, + }, + reveal_block: { + type: 'integer', + notNull: true, + }, + launched_at: { + type: 'integer', + notNull: false, + }, + launch_block: { + type: 'integer', + notNull: true, + }, + lifetime: { + type: 'integer', + notNull: true, + }, + can_update_price_function: { + type: 'boolean', + notNull: true, + }, + buckets: { + type: 'string', + notNull: true, + }, + base: { + type: 'numeric', + notNull: true, + }, + coeff: { + type: 'numeric', + notNull: true, + }, + nonalpha_discount: { + type: 'numeric', + notNull: true, + }, + no_vowel_discount: { + type: 'numeric', + notNull: true, + }, + status: { + type: 'string', + notNull: false, + }, + tx_id: { + type: 'bytea', + notNull: true, + }, + tx_index: { + type: 'smallint', + notNull: true, + }, + canonical: { + type: 'boolean', + notNull: true, + default: true, + }, + index_block_hash: { + type: 'bytea', + notNull: true, + }, + parent_index_block_hash: { + type: 'bytea', + notNull: true, + }, + microblock_hash: { + type: 'bytea', + notNull: true, + }, + microblock_sequence: { + type: 'integer', + notNull: true, + }, + microblock_canonical: { + type: 'boolean', + notNull: true, + }, + }); + + pgm.createIndex('namespaces_v2', 'index_block_hash'); + pgm.createIndex('namespaces_v2', [ + { name: 'launch_block', sort: 'DESC' }, + { name: 'microblock_sequence', sort: 'DESC' }, + { name: 'tx_index', sort: 'DESC' }, + ]); + pgm.addConstraint( + 'namespaces_v2', + 'unique_namespace_v2_id_tx_id_index_block_hash_microblock_hash', + 'UNIQUE(namespace_id, tx_id, index_block_hash, microblock_hash)' + ); + pgm.addConstraint('namespaces_v2', 'unique_namespace_id', 'UNIQUE(namespace_id)'); +}; + +exports.down = pgm => { + pgm.dropTable('namespaces_v2'); +};