2024-02-05 21:52:39 +01:00
|
|
|
import { DataSource, IsNull } from "typeorm";
|
2024-02-04 00:36:28 +01:00
|
|
|
import { ENVIRONMENT, SAVED_DATA_PATH } from "../Modules/Constants";
|
2024-01-28 11:07:10 +01:00
|
|
|
import { Song } from "../Schemas/Song";
|
|
|
|
import { ForcedCategory } from "../Schemas/ForcedCategory";
|
|
|
|
import { User } from "../Schemas/User";
|
|
|
|
import { Rating } from "../Schemas/Rating";
|
2024-02-04 22:28:42 +01:00
|
|
|
import { DiscordRole } from "../Schemas/DiscordRole";
|
2024-02-05 21:52:39 +01:00
|
|
|
import { Debug } from "../Modules/Logger";
|
2024-01-22 00:41:59 +01:00
|
|
|
|
|
|
|
export const DBSource = new DataSource({
|
|
|
|
type: "better-sqlite3",
|
2024-02-04 00:36:28 +01:00
|
|
|
database: `${SAVED_DATA_PATH}/Partypack${ENVIRONMENT !== "prod" ? `-${ENVIRONMENT}` : ""}.db`,
|
2024-01-22 00:41:59 +01:00
|
|
|
synchronize: true,
|
|
|
|
logging: false,
|
2024-01-28 11:07:10 +01:00
|
|
|
entities: [
|
|
|
|
Song,
|
|
|
|
ForcedCategory,
|
|
|
|
User,
|
2024-02-04 22:28:42 +01:00
|
|
|
Rating,
|
|
|
|
DiscordRole
|
2024-01-28 11:07:10 +01:00
|
|
|
/*join(__dirname, "..", "Schemas") + "\\*{.js,.ts}"*/ // does not work in prod
|
|
|
|
],
|
2024-01-22 00:41:59 +01:00
|
|
|
subscribers: [],
|
|
|
|
migrations: [],
|
|
|
|
enableWAL: true
|
|
|
|
});
|
|
|
|
|
|
|
|
(async () => {
|
|
|
|
await DBSource.initialize();
|
2024-02-05 21:52:39 +01:00
|
|
|
|
|
|
|
// Look for songs without a PID here so we can resolve problems before we do anything else
|
|
|
|
const SongsWithNoPID = await Song.find({ where: { PID: IsNull() } });
|
|
|
|
Debug(`We have ${SongsWithNoPID.length} song${SongsWithNoPID.length != 1 ? "s" : ""} with no PID`);
|
|
|
|
|
|
|
|
SongsWithNoPID.forEach(async (Song) => {
|
|
|
|
Debug(`Fixing up ${Song.Name} PID`);
|
|
|
|
|
|
|
|
// Existing songs that actually need separate PIDs (> 2 channels) will need to have their audio reuploaded entirely
|
|
|
|
// This is faster than checking to see if they all actually need one though...
|
|
|
|
Song.PID = Song.ID;
|
|
|
|
|
|
|
|
await Song.save();
|
|
|
|
Debug(`${Song.Name} PID is now ${Song.PID} to match ${Song.ID}`);
|
|
|
|
})
|
2024-01-22 00:41:59 +01:00
|
|
|
})();
|
|
|
|
|
|
|
|
/*
|
|
|
|
User
|
|
|
|
- discord id (primary)
|
|
|
|
- list of all songs in user's library
|
|
|
|
- list of all songs in user's published
|
|
|
|
|
|
|
|
Song
|
|
|
|
- length
|
|
|
|
- bpm
|
|
|
|
- key
|
|
|
|
- scale
|
|
|
|
- keytar/guitar
|
|
|
|
- icon url
|
|
|
|
- name
|
|
|
|
- artist
|
|
|
|
- release year
|
|
|
|
*/
|