Added auth functionality, initial work with views and field types
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
exports.up = function (knex) {
|
||||
return knex.schema
|
||||
.createTable('users', (table) => {
|
||||
table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
|
||||
table.string('email', 255).notNullable();
|
||||
table.string('password', 255).notNullable();
|
||||
table.string('firstName', 255);
|
||||
table.string('lastName', 255);
|
||||
table.boolean('isActive').defaultTo(true);
|
||||
table.timestamps(true, true);
|
||||
|
||||
table.unique(['email']);
|
||||
table.index(['email']);
|
||||
})
|
||||
.createTable('roles', (table) => {
|
||||
table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
|
||||
table.string('name', 255).notNullable();
|
||||
table.string('guardName', 255).defaultTo('api');
|
||||
table.text('description');
|
||||
table.timestamps(true, true);
|
||||
|
||||
table.unique(['name', 'guardName']);
|
||||
})
|
||||
.createTable('permissions', (table) => {
|
||||
table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
|
||||
table.string('name', 255).notNullable();
|
||||
table.string('guardName', 255).defaultTo('api');
|
||||
table.text('description');
|
||||
table.timestamps(true, true);
|
||||
|
||||
table.unique(['name', 'guardName']);
|
||||
})
|
||||
.createTable('role_permissions', (table) => {
|
||||
table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
|
||||
table.uuid('roleId').notNullable();
|
||||
table.uuid('permissionId').notNullable();
|
||||
table.timestamps(true, true);
|
||||
|
||||
table
|
||||
.foreign('roleId')
|
||||
.references('id')
|
||||
.inTable('roles')
|
||||
.onDelete('CASCADE');
|
||||
table
|
||||
.foreign('permissionId')
|
||||
.references('id')
|
||||
.inTable('permissions')
|
||||
.onDelete('CASCADE');
|
||||
table.unique(['roleId', 'permissionId']);
|
||||
})
|
||||
.createTable('user_roles', (table) => {
|
||||
table.uuid('id').primary().defaultTo(knex.raw('(UUID())'));
|
||||
table.uuid('userId').notNullable();
|
||||
table.uuid('roleId').notNullable();
|
||||
table.timestamps(true, true);
|
||||
|
||||
table
|
||||
.foreign('userId')
|
||||
.references('id')
|
||||
.inTable('users')
|
||||
.onDelete('CASCADE');
|
||||
table
|
||||
.foreign('roleId')
|
||||
.references('id')
|
||||
.inTable('roles')
|
||||
.onDelete('CASCADE');
|
||||
table.unique(['userId', 'roleId']);
|
||||
});
|
||||
};
|
||||
|
||||
exports.down = function (knex) {
|
||||
return knex.schema
|
||||
.dropTableIfExists('user_roles')
|
||||
.dropTableIfExists('role_permissions')
|
||||
.dropTableIfExists('permissions')
|
||||
.dropTableIfExists('roles')
|
||||
.dropTableIfExists('users');
|
||||
};
|
||||
Reference in New Issue
Block a user