jukebox-media-server 0.3.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,37 @@
1
+ import crypto from "node:crypto";
2
+ import fs from "node:fs";
3
+ //#region node_modules/drizzle-orm/migrator.js
4
+ function readMigrationFiles(config) {
5
+ const migrationFolderTo = config.migrationsFolder;
6
+ const migrationQueries = [];
7
+ const journalPath = `${migrationFolderTo}/meta/_journal.json`;
8
+ if (!fs.existsSync(journalPath)) throw new Error(`Can't find meta/_journal.json file`);
9
+ const journalAsString = fs.readFileSync(`${migrationFolderTo}/meta/_journal.json`).toString();
10
+ const journal = JSON.parse(journalAsString);
11
+ for (const journalEntry of journal.entries) {
12
+ const migrationPath = `${migrationFolderTo}/${journalEntry.tag}.sql`;
13
+ try {
14
+ const query = fs.readFileSync(`${migrationFolderTo}/${journalEntry.tag}.sql`).toString();
15
+ const result = query.split("--> statement-breakpoint").map((it) => {
16
+ return it;
17
+ });
18
+ migrationQueries.push({
19
+ sql: result,
20
+ bps: journalEntry.breakpoints,
21
+ folderMillis: journalEntry.when,
22
+ hash: crypto.createHash("sha256").update(query).digest("hex")
23
+ });
24
+ } catch {
25
+ throw new Error(`No file ${migrationPath} found in ${migrationFolderTo} folder`);
26
+ }
27
+ }
28
+ return migrationQueries;
29
+ }
30
+ //#endregion
31
+ //#region node_modules/drizzle-orm/better-sqlite3/migrator.js
32
+ function migrate(db, config) {
33
+ const migrations = readMigrationFiles(config);
34
+ db.dialect.migrate(migrations, db.session, config);
35
+ }
36
+ //#endregion
37
+ export { migrate };
@@ -0,0 +1,49 @@
1
+ -- Migration: rename TMDB-specific columns to neutral "external_id" +
2
+ -- "poster_url"/"backdrop_url"/"still_url" so the project can talk to any
3
+ -- metadata API. Also drop the tmdbApiKey setting row since we no longer
4
+ -- store a key.
5
+ --
6
+ -- The stored poster/backdrop/still values used to be relative TMDB paths
7
+ -- (e.g. "/abc.jpg") and the frontend prefixed image.tmdb.org. The new API
8
+ -- returns absolute URLs, so we null out the old values — a re-scan will
9
+ -- repopulate them with fully-qualified URLs.
10
+ --
11
+ -- SQLite 3.35+ supports RENAME COLUMN and DROP COLUMN, which better-sqlite3
12
+ -- ships with, so we can do this in-place without table recreation.
13
+
14
+ -- movies ---------------------------------------------------------------
15
+ ALTER TABLE `movies` ADD COLUMN `external_id` text;--> statement-breakpoint
16
+ UPDATE `movies` SET `external_id` = CAST(`tmdb_id` AS TEXT) WHERE `tmdb_id` IS NOT NULL;--> statement-breakpoint
17
+ ALTER TABLE `movies` DROP COLUMN `tmdb_id`;--> statement-breakpoint
18
+
19
+ ALTER TABLE `movies` RENAME COLUMN `poster_path` TO `poster_url`;--> statement-breakpoint
20
+ ALTER TABLE `movies` RENAME COLUMN `backdrop_path` TO `backdrop_url`;--> statement-breakpoint
21
+
22
+ UPDATE `movies` SET `poster_url` = NULL WHERE `poster_url` IS NOT NULL;--> statement-breakpoint
23
+ UPDATE `movies` SET `backdrop_url` = NULL WHERE `backdrop_url` IS NOT NULL;--> statement-breakpoint
24
+
25
+ -- shows ----------------------------------------------------------------
26
+ ALTER TABLE `shows` ADD COLUMN `external_id` text;--> statement-breakpoint
27
+ UPDATE `shows` SET `external_id` = CAST(`tmdb_id` AS TEXT) WHERE `tmdb_id` IS NOT NULL;--> statement-breakpoint
28
+ ALTER TABLE `shows` DROP COLUMN `tmdb_id`;--> statement-breakpoint
29
+
30
+ ALTER TABLE `shows` RENAME COLUMN `poster_path` TO `poster_url`;--> statement-breakpoint
31
+ ALTER TABLE `shows` RENAME COLUMN `backdrop_path` TO `backdrop_url`;--> statement-breakpoint
32
+
33
+ UPDATE `shows` SET `poster_url` = NULL WHERE `poster_url` IS NOT NULL;--> statement-breakpoint
34
+ UPDATE `shows` SET `backdrop_url` = NULL WHERE `backdrop_url` IS NOT NULL;--> statement-breakpoint
35
+
36
+ -- seasons --------------------------------------------------------------
37
+ ALTER TABLE `seasons` RENAME COLUMN `poster_path` TO `poster_url`;--> statement-breakpoint
38
+ UPDATE `seasons` SET `poster_url` = NULL WHERE `poster_url` IS NOT NULL;--> statement-breakpoint
39
+
40
+ -- episodes -------------------------------------------------------------
41
+ -- episodes.tmdb_id was never populated (always null), so no copy needed.
42
+ ALTER TABLE `episodes` ADD COLUMN `external_id` text;--> statement-breakpoint
43
+ ALTER TABLE `episodes` DROP COLUMN `tmdb_id`;--> statement-breakpoint
44
+
45
+ ALTER TABLE `episodes` RENAME COLUMN `still_path` TO `still_url`;--> statement-breakpoint
46
+ UPDATE `episodes` SET `still_url` = NULL WHERE `still_url` IS NOT NULL;--> statement-breakpoint
47
+
48
+ -- settings: drop the unused TMDB API key row ---------------------------
49
+ DELETE FROM `settings` WHERE `key` = 'tmdbApiKey';
@@ -2,7 +2,7 @@
2
2
  "version": "6",
3
3
  "dialect": "sqlite",
4
4
  "id": "9e60d80a-1f2d-4c6e-9f44-d5a6f4d9a009",
5
- "prevId": "fcf1bc05-2b5a-4a4a-ba9c-422a3d2dbfa5",
5
+ "prevId": "5d4a3c2b-1e0f-4a8b-9c7d-6e5f4a3b2c1d",
6
6
  "tables": {
7
7
  "auth_config": {
8
8
  "name": "auth_config",