Add some more models and the migrations script.
This commit is contained in:
parent
b4f57e3572
commit
d8bf0cfbd1
39
server/src/infrastructure/migrations/setup.ts
Normal file
39
server/src/infrastructure/migrations/setup.ts
Normal 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);
|
||||||
|
})
|
||||||
|
|
@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
10
server/src/models/Episodes.ts
Normal file
10
server/src/models/Episodes.ts
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
type Episode = {
|
||||||
|
title: string,
|
||||||
|
link: string,
|
||||||
|
description: string,
|
||||||
|
duration: string,
|
||||||
|
length: number,
|
||||||
|
explicit: boolean,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Episode;
|
8
server/src/models/Image.ts
Normal file
8
server/src/models/Image.ts
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
type Image = {
|
||||||
|
url: string,
|
||||||
|
title: string|undefined,
|
||||||
|
width: number|undefined,
|
||||||
|
height: number|undefined,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default Image;
|
@ -1,7 +1,6 @@
|
|||||||
type User = {
|
type User = {
|
||||||
username: string,
|
email: string,
|
||||||
password: string,
|
password: string,
|
||||||
|
|
||||||
name: string,
|
name: string,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -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);
|
|
||||||
})
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user