-
-
Notifications
You must be signed in to change notification settings - Fork 799
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
28 changed files
with
802 additions
and
172 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package migrations | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
"fmt" | ||
|
||
"github.com/navidrome/navidrome/conf" | ||
"github.com/pressly/goose/v3" | ||
) | ||
|
||
func init() { | ||
goose.AddMigrationContext(upAddLibraryTable, downAddLibraryTable) | ||
} | ||
|
||
func upAddLibraryTable(ctx context.Context, tx *sql.Tx) error { | ||
_, err := tx.ExecContext(ctx, ` | ||
create table library ( | ||
id integer primary key autoincrement, | ||
name varchar not null unique, | ||
path varchar not null unique, | ||
remote_path varchar null default '', | ||
extractor varchar null default 'taglib', | ||
last_scan_at datetime not null default '0000-00-00 00:00:00', | ||
updated_at datetime not null default current_timestamp, | ||
created_at datetime not null default current_timestamp | ||
);`) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = tx.ExecContext(ctx, fmt.Sprintf(` | ||
insert into library(id, name, path, extractor, last_scan_at) values(1, 'Music Library', '%s', '%s', current_timestamp); | ||
delete from property where id like 'LastScan-%%'; | ||
`, conf.Server.MusicFolder, conf.Server.Scanner.Extractor)) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
_, err = tx.ExecContext(ctx, ` | ||
alter table media_file add column library_id integer not null default 1 | ||
references library(id) on delete cascade; | ||
alter table album add column library_id integer not null default 1 | ||
references library(id) on delete cascade; | ||
create table if not exists library_artist | ||
( | ||
library_id integer not null default 1 | ||
references library(id) | ||
on delete cascade, | ||
artist_id varchar not null default null | ||
references artist(id) | ||
on delete cascade, | ||
constraint library_artist_ux | ||
unique (library_id, artist_id) | ||
); | ||
insert into library_artist(library_id, artist_id) select 1, id from artist; | ||
`) | ||
|
||
return err | ||
} | ||
|
||
func downAddLibraryTable(ctx context.Context, tx *sql.Tx) error { | ||
_, err := tx.ExecContext(ctx, ` | ||
alter table media_file drop column library_id; | ||
alter table album drop column library_id; | ||
drop table library_artist; | ||
drop table library; | ||
`) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package migrations | ||
|
||
import ( | ||
"context" | ||
"database/sql" | ||
|
||
"github.com/pressly/goose/v3" | ||
) | ||
|
||
func init() { | ||
goose.AddMigrationContext(upAddFolderTable, downAddFolderTable) | ||
} | ||
|
||
func upAddFolderTable(ctx context.Context, tx *sql.Tx) error { | ||
_, err := tx.ExecContext(ctx, ` | ||
create table if not exists folder( | ||
id varchar not null | ||
primary key, | ||
library_id integer not null | ||
references library (id) | ||
on delete cascade, | ||
path varchar default '' not null, | ||
name varchar default '' not null, | ||
updated_at timestamp default current_timestamp not null, | ||
created_at timestamp default current_timestamp not null, | ||
parent_id varchar default null | ||
references folder (id) | ||
on delete cascade | ||
); | ||
`) | ||
|
||
return err | ||
} | ||
|
||
func downAddFolderTable(ctx context.Context, tx *sql.Tx) error { | ||
// This code is executed when the migration is rolled back. | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.