Initial commit
This commit is contained in:
22
src/db/index.ts
Normal file
22
src/db/index.ts
Normal file
@ -0,0 +1,22 @@
|
||||
export default {
|
||||
client: process.env.DB_ENGINE || "sqlite",
|
||||
connection: (function () {
|
||||
const engine = process.env.DB_ENGINE;
|
||||
if (!engine || engine === "sqlite") {
|
||||
return process.env.DB_FILE || "voicemails.db";
|
||||
}
|
||||
if (engine === "pg") {
|
||||
if (!process.env.DB_URL) {
|
||||
throw new Error(`When DB_ENGINE=pg, DB_URL must be set.`);
|
||||
}
|
||||
return process.env.DB_URL;
|
||||
}
|
||||
throw new Error(
|
||||
`Unsupported DB_ENGINE: ${engine}. Supported: sqlite (default), pg`
|
||||
);
|
||||
})(),
|
||||
useNullAsDefault: true,
|
||||
migrations: {
|
||||
directory: "src/db/migrations",
|
||||
},
|
||||
};
|
25
src/db/migrations/20210308232030_create_voicemails_table.ts
Normal file
25
src/db/migrations/20210308232030_create_voicemails_table.ts
Normal file
@ -0,0 +1,25 @@
|
||||
import { Knex } from "knex";
|
||||
|
||||
export async function up(knex: Knex) {
|
||||
await knex.schema.createTable("voicemails", (table) => {
|
||||
table.bigInteger("messageId").primary().notNullable();
|
||||
table.bigInteger("extensionId").notNullable();
|
||||
table.dateTime("received").notNullable();
|
||||
table.string("toNumber", 32).notNullable();
|
||||
table.string("extensionNumber", 16).notNullable();
|
||||
table.string("extensionName", 64).notNullable();
|
||||
table.string("fromNumber", 32).notNullable();
|
||||
table.string("fromName", 64).notNullable();
|
||||
table.integer("duration").notNullable();
|
||||
table.string("transcriptionStatus", 32).notNullable();
|
||||
table.text("transcription");
|
||||
table.integer("ticketId");
|
||||
table.integer("contactId");
|
||||
table.string("contactableType", 32);
|
||||
table.integer("contactableId");
|
||||
});
|
||||
}
|
||||
|
||||
export async function down(knex: Knex) {
|
||||
await knex.schema.dropTableIfExists("voicemails");
|
||||
}
|
Reference in New Issue
Block a user