mnml/ops/migrations/20180913000513_create_accounts.js
2019-07-13 18:27:38 +10:00

30 lines
753 B
JavaScript
Executable File

exports.up = async knex => {
return knex.schema.createTable('accounts', table => {
table.uuid('id').primary();
table.timestamps(true, true);
table.string('name', 42).notNullable().unique();
table.string('password').notNullable();
table.string('token', 64).notNullable();
table.timestamp('token_expiry').notNullable();
table.bigInteger('balance')
.defaultTo(0)
.notNullable();
table.bool('subscribed')
.defaultTo(false)
.notNullable();
table.index('name');
table.index('id');
});
await knex.schema.raw(`
ALTER TABLE accounts
ADD CHECK (balance > 0);
`);
};
exports.down = async () => {};