Skip to content

Commit

Permalink
More fixes for migration and seeds.
Browse files Browse the repository at this point in the history
  • Loading branch information
Morgul committed May 20, 2024
1 parent 6795a54 commit b6d9bc4
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 19 deletions.
12 changes: 4 additions & 8 deletions src/server/knex/migrations/20240519053307_hash_primary_key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,15 +243,13 @@ export async function up(knex : Knex) : Promise<Knex.QueryBuilder>
// Step 5: Re-add Indexes
//------------------------------------------------------------------------------------------------------------------

knex.schema.table('account', (table) =>
await knex.schema.table('account', (table) =>
{
table.dropUnique([ 'email' ]);
table.unique('email');
});

knex.schema.table('account_role', (table) =>
await knex.schema.table('account_role', (table) =>
{
table.dropIndex([ 'account_id', 'role_id' ]);
table.unique([ 'account_id', 'role_id' ]);
});
}
Expand Down Expand Up @@ -505,15 +503,13 @@ export async function down(knex : Knex) : Promise<Knex.QueryBuilder>
// Step 5: Re-add Indexes
//------------------------------------------------------------------------------------------------------------------

knex.schema.table('account', (table) =>
await knex.schema.table('account', (table) =>
{
table.dropUnique([ 'email' ]);
table.unique('email');
});

knex.schema.table('account_role', (table) =>
await knex.schema.table('account_role', (table) =>
{
table.dropIndex([ 'account_id', 'role_id' ]);
table.unique([ 'account_id', 'role_id' ]);
});
}
Expand Down
13 changes: 2 additions & 11 deletions src/server/knex/seeds/admin_role.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,6 @@ exports.seed = async(knex) =>
permissions: '["*/*"]',
settings: '{}',
created: knex.fn.now()
},
{
account_id: '3VzoXi',
email: '[email protected]',
name: 'Lord Null',
avatar: 'https://lh6.googleusercontent.com/-uCa4jsA-_i0/AAAAAAAAAAI/AAAAAAAAAB4/chnr3xPv3_c/s96-c/photo.jpg?sz=512',
permissions: '[]',
settings: '{}',
created: knex.fn.now()
}
];

Expand All @@ -55,7 +46,7 @@ exports.seed = async(knex) =>
for(const account of admins)
{
const exists = (await knex('account').select()
.where({ account_id: account.account_id })).length > 0;
.where({ email: account.email })).length > 0;
if(!exists)
{
await knex('account').insert(account);
Expand All @@ -73,7 +64,7 @@ exports.seed = async(knex) =>
for(const account of mods)
{
const exists = (await knex('account').select()
.where({ account_id: account.account_id })).length > 0;
.where({ email: account.email })).length > 0;
if(!exists)
{
await knex('account').insert(account);
Expand Down

0 comments on commit b6d9bc4

Please sign in to comment.