Added automigtation and updated tables

This commit is contained in:
2024-10-07 19:06:23 +02:00
parent 2ca3336f1f
commit a22c2b75a6
8 changed files with 350 additions and 345 deletions

View File

@@ -0,0 +1,10 @@
ALTER TABLE "guildApps" ALTER COLUMN "userID" SET DATA TYPE varchar(32);--> statement-breakpoint
ALTER TABLE "guildApps" ALTER COLUMN "uuid" SET DATA TYPE varchar(32);--> statement-breakpoint
ALTER TABLE "settings" ALTER COLUMN "name" SET DATA TYPE varchar(32);--> statement-breakpoint
ALTER TABLE "settings" ALTER COLUMN "value" SET DATA TYPE varchar(256);--> statement-breakpoint
ALTER TABLE "staffApps" ALTER COLUMN "userID" SET DATA TYPE varchar(32);--> statement-breakpoint
ALTER TABLE "staffApps" ALTER COLUMN "uuid" SET DATA TYPE varchar(32);--> statement-breakpoint
ALTER TABLE "verifies" ALTER COLUMN "userID" SET DATA TYPE varchar(32);--> statement-breakpoint
ALTER TABLE "verifies" ALTER COLUMN "uuid" SET DATA TYPE varchar(32);--> statement-breakpoint
ALTER TABLE "waitingLists" ALTER COLUMN "userID" SET DATA TYPE varchar(32);--> statement-breakpoint
ALTER TABLE "waitingLists" ALTER COLUMN "uuid" SET DATA TYPE varchar(32);

View File

@@ -0,0 +1,232 @@
{
"id": "de8f78f2-dc26-427d-9c12-233b5d3fa301",
"prevId": "6343d646-6e68-4bcd-ae1e-5cecb4569268",
"version": "7",
"dialect": "postgresql",
"tables": {
"public.guildApps": {
"name": "guildApps",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"userID": {
"name": "userID",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true
},
"uuid": {
"name": "uuid",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.settings": {
"name": "settings",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"name": {
"name": "name",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true
},
"value": {
"name": "value",
"type": "varchar(256)",
"primaryKey": false,
"notNull": true
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.staffApps": {
"name": "staffApps",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"userID": {
"name": "userID",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true
},
"uuid": {
"name": "uuid",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.verifies": {
"name": "verifies",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"userID": {
"name": "userID",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true
},
"uuid": {
"name": "uuid",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"public.waitingLists": {
"name": "waitingLists",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "serial",
"primaryKey": true,
"notNull": true
},
"userID": {
"name": "userID",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true
},
"uuid": {
"name": "uuid",
"type": "varchar(32)",
"primaryKey": false,
"notNull": true
},
"timestamp": {
"name": "timestamp",
"type": "bigint",
"primaryKey": false,
"notNull": true
},
"createdAt": {
"name": "createdAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
},
"updatedAt": {
"name": "updatedAt",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"schemas": {},
"sequences": {},
"_meta": {
"columns": {},
"schemas": {},
"tables": {}
}
}

View File

@@ -8,6 +8,13 @@
"when": 1727906753913,
"tag": "0000_bouncy_thor_girl",
"breakpoints": true
},
{
"idx": 1,
"version": "7",
"when": 1728318584421,
"tag": "0001_quick_meggan",
"breakpoints": true
}
]
}

View File

@@ -1,36 +1,36 @@
import { bigint, pgTable, serial, text, timestamp } from "drizzle-orm/pg-core"
import { bigint, pgTable, serial, timestamp, varchar } from "drizzle-orm/pg-core"
const createdAt = timestamp("createdAt").notNull().defaultNow()
const updatedAt = timestamp("updatedAt").notNull().defaultNow().$onUpdate(() => new Date())
export const verifies = pgTable("verifies", {
id: serial("id").primaryKey(),
userID: text("userID").notNull(),
uuid: text("uuid").notNull(),
userID: varchar("userID", { length: 32 }).notNull(),
uuid: varchar("uuid", { length: 32 }).notNull(),
createdAt,
updatedAt
})
export const guildApps = pgTable("guildApps", {
id: serial("id").primaryKey(),
userID: text("userID").notNull(),
uuid: text("uuid").notNull(),
userID: varchar("userID", { length: 32 }).notNull(),
uuid: varchar("uuid", { length: 32 }).notNull(),
createdAt,
updatedAt
})
export const staffApps = pgTable("staffApps", {
id: serial("id").primaryKey(),
userID: text("userID").notNull(),
uuid: text("uuid").notNull(),
userID: varchar("userID", { length: 32 }).notNull(),
uuid: varchar("uuid", { length: 32 }).notNull(),
createdAt,
updatedAt
})
export const waitingLists = pgTable("waitingLists", {
id: serial("id").primaryKey(),
userID: text("userID").notNull(),
uuid: text("uuid").notNull(),
userID: varchar("userID", { length: 32 }).notNull(),
uuid: varchar("uuid", { length: 32 }).notNull(),
timestamp: bigint("timestamp", { mode: "number" }).notNull(),
createdAt,
updatedAt
@@ -38,8 +38,23 @@ export const waitingLists = pgTable("waitingLists", {
export const settings = pgTable("settings", {
id: serial("id").primaryKey(),
name: text("name").notNull(),
value: text("value").notNull(),
name: varchar("name", { length: 32 }).notNull(),
value: varchar("value", { length: 256 }).notNull(),
createdAt,
updatedAt
})
export type SelectVerify = typeof verifies.$inferSelect
export type InsertVerify = typeof verifies.$inferInsert
export type SelectGuildApp = typeof guildApps.$inferSelect
export type InsertGuildApp = typeof guildApps.$inferInsert
export type SelectStaffApp = typeof staffApps.$inferSelect
export type InsertStaffApp = typeof staffApps.$inferInsert
export type SelectWaitingList = typeof waitingLists.$inferSelect
export type InsertWaitingList = typeof waitingLists.$inferInsert
export type SelectSetting = typeof settings.$inferSelect
export type InsertSetting = typeof settings.$inferInsert

View File

@@ -1,21 +1,18 @@
import { Player } from "discord-player"
import { YoutubeiExtractor } from "discord-player-youtubei"
import { drizzle } from "drizzle-orm/postgres-js"
import { migrate } from "drizzle-orm/postgres-js/migrator"
import { Redis } from "ioredis"
import postgres from "postgres"
import { ExtendedClient as Client } from "~/utils/Client.js"
import env from "~/utils/Env.js"
import { color } from "~/utils/functions/colors.js"
// import { connect } from "mongoose"
import { Player } from "discord-player"
import { YoutubeiExtractor } from "discord-player-youtubei"
// import { Sequelize } from "sequelize"
import { MissingEnvVarsError } from "./Classes.js"
import loadAllEvents from "./Events/loadevents.js"
const client = new Client()
const redis = new Redis(env.prod.redisURI)
const player = new Player(client)
// const sequelize = new Sequelize({
// dialect: "sqlite",
// storage: "dev/db.sqlite"
// })
let ft: "js" | "ts"
if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT === "true") {
@@ -27,6 +24,7 @@ if (process.env.NODE_ENV === "dev" && process.env.TYPESCRIPT === "true") {
class Illegitimate {
async start() {
await this.init()
await this.migrations()
await loadAllEvents(client, ft)
// await player.extractors.loadDefault()
await player.extractors.loadDefault(ext => ext != "YouTubeExtractor")
@@ -40,14 +38,6 @@ class Illegitimate {
redis.on("ready", () => {
console.log(color("Connected to Redis", "green"))
})
// if (process.env.NODE_ENV === "dev") {
// sequelize.sync({ logging: false }).then(() => {
// console.log(color("Synced the db [dev]", "green"))
// })
// }
// connect(env.prod.mongoURI, {}).then(() => {
// console.log(color("Connected to MongoDB", "green"))
// })
}
private async init() {
@@ -68,6 +58,14 @@ class Illegitimate {
}
}
private async migrations() {
const migrationsClient = postgres(env.prod.postgresURI)
const migrations = drizzle(migrationsClient)
await migrate(migrations, {
migrationsFolder: "./src/drizzle/migrations/"
})
}
private loadMethods() {
String.prototype.removeIndents = function(this: string) {
return this.replace(/^ */gm, "")