@energyweb/node-red-contrib-green-proof-worker
Version:
## Peer dependencies
111 lines (110 loc) • 4.8 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LocalMigrationProvider = void 0;
const kysely_1 = require("kysely");
const migrationList = {
'2023-01-10T08.21.57-create-ledger-table': {
async up(db) {
await db.schema
.createTable('ledger')
.addColumn('account_id', 'text', c => c.notNull())
.addColumn('volume', 'integer', c => c.notNull())
.addColumn('root_unit_id', 'text', c => c.notNull())
.execute();
await db.schema
.createIndex('account_id_root_unit_id')
.on('ledger')
.columns(['account_id', 'root_unit_id'])
.unique()
.execute();
},
async down(db) {
await db.schema
.dropTable('ledger')
.execute();
}
},
'2024-06-12T08.21.57-create-processed-table': {
async up(db) {
await db.schema
.createTable('processed')
.addColumn('unit_id', 'text', c => c.primaryKey())
.addColumn('owner', 'text', c => c.notNull())
.addColumn('prev_owner', 'text')
.addColumn('root_unit_id', 'text', c => c.notNull())
.addColumn('volume', 'integer', c => c.notNull())
.addColumn('created_at', 'integer', c => c.notNull())
.execute();
},
async down(db) {
await db.schema
.dropTable('processed')
.execute();
}
},
'2025-01-16T21.37.00-create-acked-message-table': {
async up(db) {
await db.schema
.createTable('acked_message')
.addColumn('messageId', 'text', c => c.primaryKey())
.addColumn('created_at', 'integer', c => c.notNull())
.execute();
await db.schema
.createIndex('acked_message_created_at_index')
.on('acked_message')
.column('created_at')
.execute();
},
async down(db) {
await db.schema
.dropTable('acked_message')
.execute();
}
},
// This migration was introduced alongside changes to move message cursor to workers
// We need to clear database to fix all workers databases, and let them build state (and maybe vote) from the beginning
'2025-02-13T21.37.00-clear-data': {
async up(db) {
await db.schema
.createTable('bak_ledger')
.addColumn('account_id', 'text', c => c.notNull())
.addColumn('volume', 'integer', c => c.notNull())
.addColumn('root_unit_id', 'text', c => c.notNull())
.execute();
await db.schema
.createTable('bak_processed')
.addColumn('unit_id', 'text', c => c.primaryKey())
.addColumn('owner', 'text', c => c.notNull())
.addColumn('prev_owner', 'text')
.addColumn('root_unit_id', 'text', c => c.notNull())
.addColumn('volume', 'integer', c => c.notNull())
.addColumn('created_at', 'integer', c => c.notNull())
.execute();
await db.schema
.createTable('bak_acked_message')
.addColumn('messageId', 'text', c => c.primaryKey())
.addColumn('created_at', 'integer', c => c.notNull())
.execute();
await (0, kysely_1.sql) `INSERT INTO bak_ledger SELECT * FROM ledger;`.execute(db);
await (0, kysely_1.sql) `INSERT INTO bak_processed SELECT * FROM processed;`.execute(db);
await (0, kysely_1.sql) `INSERT INTO bak_acked_message SELECT * FROM acked_message;`.execute(db);
await db.deleteFrom('acked_message').execute();
await db.deleteFrom('processed').execute();
await db.deleteFrom('ledger').execute();
},
async down(db) {
await (0, kysely_1.sql) `INSERT INTO ledger SELECT * FROM bak_ledger;`.execute(db);
await (0, kysely_1.sql) `INSERT INTO processed SELECT * FROM bak_processed;`.execute(db);
await (0, kysely_1.sql) `INSERT INTO acked_message SELECT * FROM bak_acked_message;`.execute(db);
await db.schema.dropTable('bak_ledger').execute();
await db.schema.dropTable('bak_processed').execute();
await db.schema.dropTable('bak_acked_message').execute();
}
}
};
class LocalMigrationProvider {
getMigrations() {
return Promise.resolve(migrationList);
}
}
exports.LocalMigrationProvider = LocalMigrationProvider;