Initial commit

This commit is contained in:
2021-03-10 21:59:38 -07:00
parent 4e533f5e7b
commit fd54a8e4dd
16 changed files with 8096 additions and 0 deletions

22
src/db/index.ts Normal file
View 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",
},
};

View 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");
}