Move duration column to recordings table
This commit is contained in:
parent
0946158005
commit
1c1682fe4f
@ -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");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
@ -3,7 +3,7 @@ import ReactDOMServer from "react-dom/server";
|
|||||||
import { getNationalNumber, formatSeconds } from "./util";
|
import { getNationalNumber, formatSeconds } from "./util";
|
||||||
import { DateTime } from "luxon";
|
import { DateTime } from "luxon";
|
||||||
import type { Contact } from "./types";
|
import type { Contact } from "./types";
|
||||||
import type { StoredVoicemail } from "knex/types/tables";
|
import type { StoredVoicemail, StoredRecording } from "knex/types/tables";
|
||||||
|
|
||||||
export function getTicketSubject(
|
export function getTicketSubject(
|
||||||
voicemail: StoredVoicemail,
|
voicemail: StoredVoicemail,
|
||||||
@ -14,7 +14,10 @@ export function getTicketSubject(
|
|||||||
})`;
|
})`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getTicketBody(vm: StoredVoicemail, contact?: Contact) {
|
export function getTicketBody(
|
||||||
|
vm: StoredVoicemail & StoredRecording,
|
||||||
|
contact?: Contact
|
||||||
|
) {
|
||||||
return ReactDOMServer.renderToStaticMarkup(
|
return ReactDOMServer.renderToStaticMarkup(
|
||||||
<div>
|
<div>
|
||||||
<div>
|
<div>
|
||||||
|
@ -243,7 +243,6 @@ export function ticketize(
|
|||||||
extensionName: extension.name,
|
extensionName: extension.name,
|
||||||
fromNumber: message.from.phoneNumber,
|
fromNumber: message.from.phoneNumber,
|
||||||
fromName: message.from.name,
|
fromName: message.from.name,
|
||||||
duration: recording.duration,
|
|
||||||
transcriptionStatus: transcription.status,
|
transcriptionStatus: transcription.status,
|
||||||
transcription: transcription.text,
|
transcription: transcription.text,
|
||||||
});
|
});
|
||||||
@ -251,6 +250,7 @@ export function ticketize(
|
|||||||
messageId: message.id,
|
messageId: message.id,
|
||||||
mimeType: recording.mimeType,
|
mimeType: recording.mimeType,
|
||||||
audio: new Uint8Array(recording.audio),
|
audio: new Uint8Array(recording.audio),
|
||||||
|
duration: recording.duration,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -116,7 +116,6 @@ declare module "knex/types/tables" {
|
|||||||
extensionName: string;
|
extensionName: string;
|
||||||
fromNumber: string;
|
fromNumber: string;
|
||||||
fromName: string;
|
fromName: string;
|
||||||
duration: number;
|
|
||||||
transcriptionStatus: TranscriptionStatus;
|
transcriptionStatus: TranscriptionStatus;
|
||||||
transcription: string | null;
|
transcription: string | null;
|
||||||
ticketId?: number;
|
ticketId?: number;
|
||||||
@ -129,6 +128,7 @@ declare module "knex/types/tables" {
|
|||||||
messageId: number;
|
messageId: number;
|
||||||
mimeType: string;
|
mimeType: string;
|
||||||
audio: ArrayBuffer;
|
audio: ArrayBuffer;
|
||||||
|
duration: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface Tables {
|
interface Tables {
|
||||||
|
Loading…
Reference in New Issue
Block a user