From d8bf0cfbd17725e1a961563fbcaa48f023d69fe5 Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Tue, 20 Feb 2024 21:03:53 -0500 Subject: [PATCH] Add some more models and the migrations script. --- server/src/infrastructure/migrations/setup.ts | 39 +++++++++++++++++++ server/src/models/Channel.ts | 21 +++++----- server/src/models/Episodes.ts | 10 +++++ server/src/models/Image.ts | 8 ++++ server/src/models/User.ts | 3 +- server/src/setup.ts | 27 ------------- 6 files changed, 68 insertions(+), 40 deletions(-) create mode 100644 server/src/infrastructure/migrations/setup.ts create mode 100644 server/src/models/Episodes.ts create mode 100644 server/src/models/Image.ts delete mode 100644 server/src/setup.ts diff --git a/server/src/infrastructure/migrations/setup.ts b/server/src/infrastructure/migrations/setup.ts new file mode 100644 index 0000000..63ec2fa --- /dev/null +++ b/server/src/infrastructure/migrations/setup.ts @@ -0,0 +1,39 @@ +import { createConnection } from "mariadb"; + +// @ts-ignore +const SQL_ROOT_DIR: string = import.meta.dir + '/../../../sql'; + +async function run() { + const connection = await createConnection({ + host: process.env.DATABASE_HOST, + user: process.env.DATABASE_USER, + password: process.env.DATABASE_PASSWORD, + database: process.env.DATABASE_SCHEMA + }); + + const createUserQuery: string = await Bun.file(SQL_ROOT_DIR + '/01-users.sql').text(); + const createImagesQuery: string = await Bun.file(SQL_ROOT_DIR + '/02-images.sql').text(); + const createChannelsQuery: string = await Bun.file(SQL_ROOT_DIR + '/03-channels.sql').text(); + const createEpisodesQuery: string = await Bun.file(SQL_ROOT_DIR + '/04-episodes.sql').text(); + + + const results = Promise.all([ + connection.query(createUserQuery), + connection.query(createImagesQuery), + connection.query(createChannelsQuery), + connection.query(createEpisodesQuery) + ]); + + return results; +} + +run() + .then(r => { + console.log(r); + process.exit(0); + }) + .catch(e => { + console.error(e); + process.exit(1); + }) + diff --git a/server/src/models/Channel.ts b/server/src/models/Channel.ts index 64adf08..1ab9c1a 100644 --- a/server/src/models/Channel.ts +++ b/server/src/models/Channel.ts @@ -1,12 +1,11 @@ -export default class Channel { - private name: string; - private slug: string; +type Channel = { + name: string, + description: string, + link: string, + lanuage: string, + copyright: string|undefined, + explicit: boolean, + category: string, +}; - private constructor(name: string) { - this.name = name; - } - - public static generateSlug(name: string): string { - return name; - } -} +export default Channel; diff --git a/server/src/models/Episodes.ts b/server/src/models/Episodes.ts new file mode 100644 index 0000000..a12e1f9 --- /dev/null +++ b/server/src/models/Episodes.ts @@ -0,0 +1,10 @@ +type Episode = { + title: string, + link: string, + description: string, + duration: string, + length: number, + explicit: boolean, +}; + +export default Episode; diff --git a/server/src/models/Image.ts b/server/src/models/Image.ts new file mode 100644 index 0000000..31c43c1 --- /dev/null +++ b/server/src/models/Image.ts @@ -0,0 +1,8 @@ +type Image = { + url: string, + title: string|undefined, + width: number|undefined, + height: number|undefined, +}; + +export default Image; diff --git a/server/src/models/User.ts b/server/src/models/User.ts index 96f8b7f..c53096e 100644 --- a/server/src/models/User.ts +++ b/server/src/models/User.ts @@ -1,7 +1,6 @@ type User = { - username: string, + email: string, password: string, - name: string, }; diff --git a/server/src/setup.ts b/server/src/setup.ts deleted file mode 100644 index 1275cb8..0000000 --- a/server/src/setup.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { createPool } from "mariadb"; - -async function run() { - const pool = createPool({ - host: process.env.DATABASE_HOST, - user: process.env.DATABASE_USER, - password: process.env.DATABASE_PASSWORD, - database: process.env.DATABASE_SCHEMA - }); - - const createUserBuffer: string = await Bun.file('./sql/users.sql').text(); - const conn = await pool.getConnection(); - const results = await conn.query(createUserBuffer); - - return results; -} - -run() - .then(r => { - console.log(r); - process.exit(0); - }) - .catch(e => { - console.error(e); - process.exit(1); - }) -