Add some more models and the migrations script.

This commit is contained in:
Dave Smith-Hayes 2024-02-20 21:03:53 -05:00
parent b4f57e3572
commit d8bf0cfbd1
6 changed files with 68 additions and 40 deletions

View File

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

View File

@ -1,12 +1,11 @@
export default class Channel { type Channel = {
private name: string; name: string,
private slug: string; description: string,
link: string,
lanuage: string,
copyright: string|undefined,
explicit: boolean,
category: string,
};
private constructor(name: string) { export default Channel;
this.name = name;
}
public static generateSlug(name: string): string {
return name;
}
}

View File

@ -0,0 +1,10 @@
type Episode = {
title: string,
link: string,
description: string,
duration: string,
length: number,
explicit: boolean,
};
export default Episode;

View File

@ -0,0 +1,8 @@
type Image = {
url: string,
title: string|undefined,
width: number|undefined,
height: number|undefined,
};
export default Image;

View File

@ -1,7 +1,6 @@
type User = { type User = {
username: string, email: string,
password: string, password: string,
name: string, name: string,
}; };

View File

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