-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path20180617203030_users.ts
41 lines (37 loc) · 1.5 KB
/
20180617203030_users.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import * as Knex from "knex";
import dbSchemaAddTimestamps from '../src/utils/dbSchemaAddTimestamps';
import { USER_ROLES } from '../src/constants';
exports.up = async function (knex: Knex): Promise<any> {
await knex.schema.createTable('users', (table) => {
table.increments('id').notNullable().primary();
table.uuid('uuid').notNullable().unique();
table.string('firstName');
table.string('lastName');
table.string('password');
table.enum('roleType', USER_ROLES);
table.index(['roleType']);
dbSchemaAddTimestamps({ knex, table });
});
await knex.schema.createTable('emails', (table) => {
table.increments('id').notNullable().primary();
table.uuid('userId').notNullable();
table.string('email', 100).notNullable();
table.boolean('verified').notNullable().defaultTo(false);
table.boolean('primary').notNullable().defaultTo(false);
table.unique(['email', 'verified']);
dbSchemaAddTimestamps({ knex, table });
});
await knex.schema.createTable('tokens', (table) => {
table.increments('id').notNullable().primary();
table.uuid('userId').notNullable();
table.string('token', 255).notNullable();
table.boolean('blacklisted').notNullable().defaultTo(false);
table.unique(['userId', 'token']);
dbSchemaAddTimestamps({ knex, table });
});
};
exports.down = async function (knex: Knex): Promise<any> {
await knex.schema.dropTableIfExists('users');
await knex.schema.dropTableIfExists('emails');
await knex.schema.dropTableIfExists('tokens');
};