From 39b865664c3c670d0c6bba622d4a168bd2600123 Mon Sep 17 00:00:00 2001 From: Paolo Brasolin <paolo.brasolin@eurac.edu> Date: Thu, 10 Mar 2022 08:12:09 +0100 Subject: [PATCH] feat: create words table #be --- backend/migrations/20220309170000_pgcrypto.ts | 9 +++++++++ backend/migrations/20220309170943_words.ts | 17 +++++++++++++++++ 2 files changed, 26 insertions(+) create mode 100644 backend/migrations/20220309170000_pgcrypto.ts create mode 100644 backend/migrations/20220309170943_words.ts diff --git a/backend/migrations/20220309170000_pgcrypto.ts b/backend/migrations/20220309170000_pgcrypto.ts new file mode 100644 index 0000000..4dc10e7 --- /dev/null +++ b/backend/migrations/20220309170000_pgcrypto.ts @@ -0,0 +1,9 @@ +import { Knex } from "knex"; + +export async function up(knex: Knex): Promise<void> { + return knex.schema.raw('CREATE EXTENSION IF NOT EXISTS "pgcrypto"'); +} + +export async function down(knex: Knex): Promise<void> { + return knex.schema.raw('DROP EXTENSION IF EXISTS "pgcrypto"'); +} diff --git a/backend/migrations/20220309170943_words.ts b/backend/migrations/20220309170943_words.ts new file mode 100644 index 0000000..b8922ae --- /dev/null +++ b/backend/migrations/20220309170943_words.ts @@ -0,0 +1,17 @@ +import { Knex } from "knex"; + +export async function up(knex: Knex): Promise<void> { + return knex.schema.createTable("words", function (table) { + table.uuid("id").primary().defaultTo(knex.raw("gen_random_uuid()")); + table.string("page_id").index().notNullable(); + table.integer("word_id").index().notNullable(); + table.unique(["page_id", "word_id"]); + table.binary("image").notNullable(); + table.string("ocr_transcript"); + table.float("ocr_confidence"); + }); +} + +export async function down(knex: Knex): Promise<void> { + return knex.schema.dropTable("words"); +} -- GitLab