Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Updated dev-reinit to recreate knex tables. #8588

Merged
merged 5 commits into from
Aug 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"local": "npm run dev-docker && cross-env VITE_LOCAL_BUILD=true LOCAL=true concurrently -n agones,server,worldserver,mediaserver,client,files npm:dev-agones-silent \"cd packages/server && npm run start\" \"cd packages/instanceserver && npm run start\" \"cd packages/instanceserver && npm run start-channel\" \"cd packages/client && npm run local\" \"cd packages/server && npm run serve-local-files\"",
"make-user-admin": "cross-env ts-node --swc scripts/make-user-admin.ts",
"migrate": "cd packages/server-core && npm run migrate",
"migrate:rollback": "cd packages/server-core && npm run migrate:rollback",
"postinstall": "patch-package --exclude ./node_modules/@mui/",
"precommit": "no-master-commits -b master",
"prepare-database": "cross-env APP_ENV=production PREPARE_DATABASE=true EXIT_ON_DB_INIT=true ts-node --swc packages/server/src/index.ts",
Expand Down
20 changes: 16 additions & 4 deletions packages/server-core/migration.stub
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,13 @@ import type { Knex } from 'knex'
* @returns { Promise<void> }
*/
export async function up(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(TABLE_NAME)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(TABLE_NAME)

if (tableExists === false) {
await knex.schema.createTable(TABLE_NAME, (table) => {
await trx.schema.createTable(TABLE_NAME, (table) => {
//@ts-ignore
table.uuid('id').collate('utf8mb4_bin').primary()

Expand All @@ -43,16 +46,25 @@ export async function up(knex: Knex): Promise<void> {
table.dateTime('updatedAt').notNullable()
})
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}

/**
* @param { import("knex").Knex } knex
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(TABLE_NAME)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(TABLE_NAME)

if (tableExists === true) {
await knex.schema.dropTable(TABLE_NAME)
await trx.schema.dropTable(TABLE_NAME)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
1 change: 1 addition & 0 deletions packages/server-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"test": "mocha",
"validate": "npm run build && npm run test",
"migrate": "knex migrate:latest",
"migrate:rollback": "knex migrate:rollback --all",
"migrate:make": "knex --migrations-directory ./ migrate:make"
},
"dependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(analyticsPath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(analyticsPath)

if (tableExists === true) {
await knex.schema.dropTable(analyticsPath)
await trx.schema.dropTable(analyticsPath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(botCommandPath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(botCommandPath)

if (tableExists === true) {
await knex.schema.dropTable(botCommandPath)
await trx.schema.dropTable(botCommandPath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,15 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(botPath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(botPath)

if (tableExists === true) {
await knex.schema.dropTable(botPath)
await trx.schema.dropTable(botPath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,15 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(buildStatusPath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(buildStatusPath)

if (tableExists === true) {
await knex.schema.dropTable(buildStatusPath)
await trx.schema.dropTable(buildStatusPath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,15 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(matchInstancePath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(matchInstancePath)

if (tableExists === true) {
await knex.schema.dropTable(matchInstancePath)
await trx.schema.dropTable(matchInstancePath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ export async function up(knex: Knex): Promise<void> {
})

await trx.raw('SET FOREIGN_KEY_CHECKS=1')

await trx.commit()
}
}
Expand All @@ -80,9 +79,15 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(matchUserPath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(matchUserPath)

if (tableExists === true) {
await knex.schema.dropTable(matchUserPath)
await trx.schema.dropTable(matchUserPath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,20 @@ export async function up(knex: Knex): Promise<void> {
})

await trx.raw('SET FOREIGN_KEY_CHECKS=1')

await trx.commit()
}
}

export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(staticResourcePath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(staticResourcePath)

if (tableExists === true) {
await knex.schema.dropTable(staticResourcePath)
await trx.schema.dropTable(staticResourcePath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,15 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(instanceAttendancePath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(instanceAttendancePath)

if (tableExists === true) {
await knex.schema.dropTable(instanceAttendancePath)
await trx.schema.dropTable(instanceAttendancePath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ export async function up(knex: Knex): Promise<void> {
})

await trx.raw('SET FOREIGN_KEY_CHECKS=1')

await trx.commit()
}
}
Expand All @@ -90,9 +89,15 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(instanceAuthorizedUserPath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(instanceAuthorizedUserPath)

if (tableExists === true) {
await knex.schema.dropTable(instanceAuthorizedUserPath)
await trx.schema.dropTable(instanceAuthorizedUserPath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,15 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(projectPermissionTypePath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(projectPermissionTypePath)

if (tableExists === true) {
await knex.schema.dropTable(projectPermissionTypePath)
await trx.schema.dropTable(projectPermissionTypePath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,15 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(projectPermissionPath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(projectPermissionPath)

if (tableExists === true) {
await knex.schema.dropTable(projectPermissionPath)
await trx.schema.dropTable(projectPermissionPath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ export const download = async (projectName: string, storageProviderName?: string
// npmInstallProcess.once('error', resolve)
// npmInstallProcess.once('disconnect', resolve)
// npmInstallProcess.stdout.on('data', (data) => logger.info(data.toString()))
// npmInstallProcess.stderr.on('data', (data) => logger.error(data.toString()))
// }).then((result) => logger.info(result))
// await Promise.race([
// npmInstallPromise,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ export async function up(knex: Knex): Promise<void> {
})

await trx.raw('SET FOREIGN_KEY_CHECKS=1')

await trx.commit()
}
}
Expand All @@ -96,9 +95,15 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(recordingResourcePath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(recordingResourcePath)

if (tableExists === true) {
await knex.schema.dropTable(recordingResourcePath)
await trx.schema.dropTable(recordingResourcePath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,20 @@ export async function up(knex: Knex): Promise<void> {
})

await trx.raw('SET FOREIGN_KEY_CHECKS=1')

await trx.commit()
}
}

export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(recordingPath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(recordingPath)

if (tableExists === true) {
await knex.schema.dropTable(recordingPath)
await trx.schema.dropTable(recordingPath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,15 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(routePath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(routePath)

if (tableExists === true) {
await knex.schema.dropTable(routePath)
await trx.schema.dropTable(routePath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,15 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(scopeTypePath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(scopeTypePath)

if (tableExists === true) {
await knex.schema.dropTable(scopeTypePath)
await trx.schema.dropTable(scopeTypePath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,15 @@ export async function up(knex: Knex): Promise<void> {
* @returns { Promise<void> }
*/
export async function down(knex: Knex): Promise<void> {
const tableExists = await knex.schema.hasTable(scopePath)
const trx = await knex.transaction()
await trx.raw('SET FOREIGN_KEY_CHECKS=0')

const tableExists = await trx.schema.hasTable(scopePath)

if (tableExists === true) {
await knex.schema.dropTable(scopePath)
await trx.schema.dropTable(scopePath)
}

await trx.raw('SET FOREIGN_KEY_CHECKS=1')
await trx.commit()
}
Loading
Loading