Move duration column to recordings table
This commit is contained in:
@ -0,0 +1,47 @@
|
||||
import { Knex } from "knex";
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
return knex.transaction(async (trx) => {
|
||||
await trx.schema.alterTable("recordings", (table) => {
|
||||
table.integer("duration");
|
||||
});
|
||||
|
||||
// transfer recording durations from voicemails table
|
||||
await trx("recordings").update({
|
||||
duration: knex("voicemails")
|
||||
.select("duration")
|
||||
.where("messageId", knex.raw("??", "recordings.messageId")),
|
||||
});
|
||||
|
||||
// now we can make duration column not-nullable
|
||||
await trx.schema.alterTable("recordings", (table) => {
|
||||
table.integer("duration").notNullable().alter();
|
||||
});
|
||||
|
||||
await trx.schema.alterTable("voicemails", (table) => {
|
||||
table.dropColumn("duration");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {
|
||||
return knex.transaction(async (trx) => {
|
||||
await trx.schema.alterTable("voicemails", (table) => {
|
||||
table.integer("duration");
|
||||
});
|
||||
|
||||
await trx("voicemails").update({
|
||||
duration: knex("recordings")
|
||||
.select("duration")
|
||||
.where("messageId", knex.raw("??", "voicemails.messageId")),
|
||||
});
|
||||
|
||||
await trx.schema.alterTable("voicemails", (table) => {
|
||||
table.integer("duration").notNullable().alter();
|
||||
});
|
||||
|
||||
await trx.schema.alterTable("recordings", (table) => {
|
||||
table.dropColumn("duration");
|
||||
});
|
||||
});
|
||||
}
|
Reference in New Issue
Block a user