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