mirror of
https://github.com/alexgo-io/stacks-blockchain-api.git
synced 2026-01-12 16:53:19 +08:00
98 lines
1.9 KiB
JavaScript
98 lines
1.9 KiB
JavaScript
/** @param { import("node-pg-migrate").MigrationBuilder } pgm */
|
|
exports.up = pgm => {
|
|
pgm.createTable('names', {
|
|
id: {
|
|
type: 'serial',
|
|
primaryKey: true,
|
|
},
|
|
name: {
|
|
type: 'string',
|
|
notNull: true,
|
|
},
|
|
address: {
|
|
type: 'string',
|
|
notNull: true,
|
|
},
|
|
registered_at: {
|
|
type: 'integer',
|
|
notNull: true,
|
|
},
|
|
expire_block: {
|
|
type: 'integer',
|
|
notNull: true,
|
|
},
|
|
zonefile_hash: {
|
|
type: 'string',
|
|
notNull: true,
|
|
},
|
|
namespace_id: {
|
|
notNull: true,
|
|
type: 'string'
|
|
},
|
|
grace_period: {
|
|
type: 'string',
|
|
notNull: false,
|
|
},
|
|
renewal_deadline: {
|
|
type: 'integer',
|
|
notNull: false,
|
|
},
|
|
resolver: {
|
|
type: 'string',
|
|
notNull: false,
|
|
},
|
|
tx_id: {
|
|
type: 'bytea',
|
|
notNull: false,
|
|
},
|
|
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: false
|
|
},
|
|
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', 'namespace_id');
|
|
pgm.createIndex('names', 'index_block_hash');
|
|
pgm.createIndex('names', [
|
|
{ name: 'registered_at', sort: 'DESC' },
|
|
{ name: 'microblock_sequence', sort: 'DESC' },
|
|
{ name: 'tx_index', sort: 'DESC' },
|
|
{ name: 'event_index', sort: 'DESC' }
|
|
]);
|
|
pgm.addConstraint(
|
|
'names',
|
|
'unique_name_tx_id_index_block_hash_microblock_hash_event_index',
|
|
'UNIQUE(name, tx_id, index_block_hash, microblock_hash, event_index)'
|
|
);
|
|
}
|