Merge pull request #944 from automatisch/user-role

feat: Introduce role column to user model
This commit is contained in:
Ömer Faruk Aydın
2023-02-18 14:29:11 +01:00
committed by GitHub
3 changed files with 30 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
import { Knex } from 'knex';
export async function up(knex: Knex): Promise<void> {
return knex.schema.table('users', async (table) => {
table.string('role');
await knex('users').update({ role: 'admin' });
});
}
export async function down(knex: Knex): Promise<void> {
return knex.schema.table('users', (table) => {
table.dropColumn('role');
});
}

View File

@@ -0,0 +1,13 @@
import { Knex } from 'knex';
export async function up(knex: Knex): Promise<void> {
return knex.schema.alterTable('users', (table) => {
table.string('role').notNullable().alter();
});
}
export async function down(knex: Knex): Promise<void> {
return knex.schema.alterTable('users', (table) => {
table.string('role').nullable().alter();
});
}

View File

@@ -10,6 +10,7 @@ class User extends Base {
id!: string;
email!: string;
password!: string;
role: string;
connections?: Connection[];
flows?: Flow[];
steps?: Step[];
@@ -25,6 +26,7 @@ class User extends Base {
id: { type: 'string', format: 'uuid' },
email: { type: 'string', format: 'email', minLength: 1, maxLength: 255 },
password: { type: 'string', minLength: 1, maxLength: 255 },
role: { type: 'string', enum: ['admin', 'user'] },
},
};