Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
tank
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AURA
tank
Commits
bc3efa7b
Verified
Commit
bc3efa7b
authored
3 months ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
feat: remove Playlist & PlaylistEntry from migrations
parent
f7bfa7d1
Branches
remove-playlists
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
store/migrations.go
+7
-144
7 additions, 144 deletions
store/migrations.go
with
7 additions
and
144 deletions
store/migrations.go
+
7
−
144
View file @
bc3efa7b
...
...
@@ -33,33 +33,6 @@ var (
Migrate
:
func
(
tx
*
gorm
.
DB
)
error
{
return
nil
},
Rollback
:
func
(
tx
*
gorm
.
DB
)
error
{
return
nil
},
},
{
ID
:
"201905160033"
,
Migrate
:
func
(
tx
*
gorm
.
DB
)
error
{
type
PlaylistEntry
struct
{
ID
uint64
`json:"-" gorm:"primaryKey"`
PlaylistID
uint64
`json:"-" gorm:"not null;index;uniqueIndex:unique_playlist_line_numbers"`
LineNum
uint
`json:"-" gorm:"not null;uniqueIndex:unique_playlist_line_numbers"`
URI
string
`json:"uri" gorm:"size:1024"`
File
*
File
`json:"file,omitempty" gorm:"associationAutoUpdate:false;associationAutoCreate:false"`
FileID
*
uint64
`json:"-" gorm:"index"`
}
type
Playlist
struct
{
ID
uint64
`json:"id" gorm:"primaryKey"`
CreatedAt
time
.
Time
`json:"created"`
UpdatedAt
time
.
Time
`json:"updated"`
Description
string
`json:"description"`
ShowName
string
`json:"show" gorm:"not null;index"`
Show
Show
`json:"-" gorm:"associationForeignKey:Name"`
Entries
[]
PlaylistEntry
`json:"entries,omitempty"`
}
return
tx
.
AutoMigrate
(
&
Playlist
{})
},
Rollback
:
func
(
tx
*
gorm
.
DB
)
error
{
return
tx
.
Migrator
()
.
DropColumn
(
&
Playlist
{},
"description"
)
},
},
{
ID
:
"201905291602"
,
Migrate
:
func
(
tx
*
gorm
.
DB
)
error
{
...
...
@@ -115,36 +88,6 @@ var (
return
tx
.
Migrator
()
.
DropConstraint
(
&
ImportLog
{},
"file_id"
)
},
},
{
ID
:
"201908110945"
,
Migrate
:
func
(
tx
*
gorm
.
DB
)
error
{
type
PlaylistEntry
struct
{
ID
uint64
`json:"-" gorm:"primaryKey"`
PlaylistID
uint64
`json:"-" gorm:"not null;index;uniqueIndex:unique_playlist_line_numbers"`
LineNum
uint
`json:"-" gorm:"not null;uniqueIndex:unique_playlist_line_numbers"`
URI
string
`json:"uri" gorm:"size:1024"`
File
*
File
`json:"file,omitempty" gorm:"associationAutoUpdate:false;associationAutoCreate:false"`
FileID
*
uint64
`json:"-" gorm:"index"`
}
type
Playlist
struct
{
ID
uint64
`json:"id" gorm:"primaryKey"`
CreatedAt
time
.
Time
`json:"created"`
UpdatedAt
time
.
Time
`json:"updated"`
Description
string
`json:"description"`
PlayoutMode
string
`json:"playoutMode"`
ShowName
string
`json:"show" gorm:"not null;index"`
Show
Show
`json:"-" gorm:"associationForeignKey:Name"`
Entries
[]
PlaylistEntry
`json:"entries,omitempty"`
}
return
tx
.
AutoMigrate
(
&
Playlist
{})
},
Rollback
:
func
(
tx
*
gorm
.
DB
)
error
{
return
tx
.
Migrator
()
.
DropColumn
(
&
Playlist
{},
"playout_mode"
)
},
},
{
ID
:
"201908150104"
,
Migrate
:
func
(
tx
*
gorm
.
DB
)
error
{
...
...
@@ -188,30 +131,6 @@ var (
return
tx
.
Migrator
()
.
DropColumn
(
&
File
{},
"metadata__isrc"
)
},
},
{
ID
:
"202006130203"
,
Migrate
:
func
(
tx
*
gorm
.
DB
)
error
{
type
PlaylistEntry
struct
{
ID
uint64
`json:"-" gorm:"primaryKey"`
PlaylistID
uint64
`json:"-" gorm:"not null;index;uniqueIndex:unique_playlist_line_numbers"`
LineNum
uint
`json:"-" gorm:"not null;uniqueIndex:unique_playlist_line_numbers"`
URI
string
`json:"uri" gorm:"size:1024"`
Duration
*
time
.
Duration
`json:"duration,omitempty"`
File
*
File
`json:"file,omitempty" gorm:"associationAutoUpdate:false;associationAutoCreate:false"`
FileID
*
uint64
`json:"-" gorm:"index"`
}
// actually all playlists would need to be verified if they still fit the new constraint
// that only allows a single non-file entry with duration == NULL per playlist.
// However, we are still pre-first-release and all migrations will likely be squashed before that
// release anyway...
return
tx
.
AutoMigrate
(
&
PlaylistEntry
{})
},
Rollback
:
func
(
tx
*
gorm
.
DB
)
error
{
return
tx
.
Migrator
()
.
DropColumn
(
&
PlaylistEntry
{},
"duration"
)
},
},
{
ID
:
"202309141500"
,
Migrate
:
func
(
tx
*
gorm
.
DB
)
error
{
...
...
@@ -227,21 +146,7 @@ var (
Duration
float64
`json:"duration"`
}
if
err
:=
tx
.
Migrator
()
.
AlterColumn
(
&
File
{},
"duration"
);
err
!=
nil
{
return
err
}
type
PlaylistEntry
struct
{
ID
uint64
`json:"-" gorm:"primaryKey"`
PlaylistID
uint64
`json:"-" gorm:"not null;index;uniqueIndex:unique_playlist_line_numbers"`
LineNum
uint
`json:"-" gorm:"not null;uniqueIndex:unique_playlist_line_numbers"`
URI
string
`json:"uri" gorm:"size:1024"`
Duration
*
float64
`json:"duration,omitempty"`
File
*
File
`json:"file,omitempty" gorm:"associationAutoUpdate:false;associationAutoCreate:false"`
FileID
*
uint64
`json:"-" gorm:"index"`
}
return
tx
.
Migrator
()
.
AlterColumn
(
&
PlaylistEntry
{},
"duration"
)
return
tx
.
Migrator
()
.
AlterColumn
(
&
File
{},
"duration"
)
},
Rollback
:
func
(
tx
*
gorm
.
DB
)
error
{
type
File
struct
{
...
...
@@ -256,11 +161,7 @@ var (
Duration
time
.
Duration
`json:"duration"`
}
if
err
:=
tx
.
Migrator
()
.
AlterColumn
(
&
File
{},
"duration"
);
err
!=
nil
{
return
err
}
return
tx
.
Migrator
()
.
AlterColumn
(
&
Playlist
{},
"duration"
)
return
tx
.
Migrator
()
.
AlterColumn
(
&
File
{},
"duration"
)
},
},
{
...
...
@@ -282,41 +183,26 @@ var (
Size
uint64
`json:"size"`
Duration
float64
`json:"duration"`
}
type
Playlist
struct
{
ID
uint64
`json:"id" gorm:"primaryKey"`
CreatedAt
time
.
Time
`json:"created"`
UpdatedAt
time
.
Time
`json:"updated"`
Description
string
`json:"description"`
PlayoutMode
string
`json:"playoutMode" gorm:"not null;default:'linear'"`
ShowID
uint64
`json:"showId" gorm:"not null;index"`
Show
Show
`json:"-" gorm:"associationForeignKey:ID"`
Entries
[]
PlaylistEntry
`json:"entries"`
}
if
err
:=
tx
.
Migrator
()
.
DropConstraint
(
&
File
{},
"show_name"
);
err
!=
nil
{
return
err
}
if
err
:=
tx
.
Migrator
()
.
DropConstraint
(
&
Playlist
{},
"show_name"
);
err
!=
nil
{
return
err
}
return
tx
.
AutoMigrate
(
&
Show
{},
&
File
{},
&
Playlist
{})
return
tx
.
AutoMigrate
(
&
Show
{},
&
File
{})
},
Rollback
:
func
(
tx
*
gorm
.
DB
)
error
{
if
err
:=
tx
.
Migrator
()
.
DropColumn
(
&
Show
{},
"id"
);
err
!=
nil
{
return
err
}
if
err
:=
tx
.
Migrator
()
.
DropColumn
(
&
File
{},
"show_id"
);
err
!=
nil
{
return
err
}
return
tx
.
Migrator
()
.
DropColumn
(
&
Playlist
{},
"show_id"
)
return
tx
.
Migrator
()
.
DropColumn
(
&
File
{},
"show_id"
)
},
},
}
)
func
initialMigration
(
tx
*
gorm
.
DB
)
(
err
error
)
{
if
err
=
tx
.
AutoMigrate
(
&
Show
{},
&
File
{},
&
ImportLog
{}
,
&
Playlist
{},
&
PlaylistEntry
{}
);
err
!=
nil
{
if
err
=
tx
.
AutoMigrate
(
&
Show
{},
&
File
{},
&
ImportLog
{});
err
!=
nil
{
return
err
}
...
...
@@ -331,30 +217,7 @@ func initialMigration(tx *gorm.DB) (err error) {
if
err
=
tx
.
Exec
(
"ALTER TABLE import_logs DROP CONSTRAINT fk_import_logs_file"
)
.
Error
;
err
!=
nil
{
return
err
}
if
err
=
tx
.
Exec
(
"ALTER TABLE import_logs ADD CONSTRAINT fk_import_logs_file FOREIGN KEY (file_id) REFERENCES files(id) ON UPDATE CASCADE ON DELETE CASCADE "
)
.
Error
;
err
!=
nil
{
return
err
}
if
err
=
tx
.
Exec
(
"ALTER TABLE playlists DROP CONSTRAINT fk_playlists_show"
)
.
Error
;
err
!=
nil
{
return
err
}
if
err
=
tx
.
Exec
(
"ALTER TABLE playlists ADD CONSTRAINT fk_playlists_show FOREIGN KEY (show_id) REFERENCES shows(id) ON UPDATE CASCADE ON DELETE CASCADE "
)
.
Error
;
err
!=
nil
{
return
err
}
if
err
=
tx
.
Exec
(
"ALTER TABLE playlist_entries DROP CONSTRAINT fk_playlist_entries_file"
)
.
Error
;
err
!=
nil
{
return
err
}
if
err
=
tx
.
Exec
(
"ALTER TABLE playlist_entries ADD CONSTRAINT fk_playlist_entries_file FOREIGN KEY (file_id) REFERENCES files(id) ON UPDATE CASCADE ON DELETE RESTRICT "
)
.
Error
;
err
!=
nil
{
return
err
}
if
err
=
tx
.
Exec
(
"ALTER TABLE playlist_entries DROP CONSTRAINT fk_playlists_entries"
)
.
Error
;
err
!=
nil
{
return
err
}
if
err
=
tx
.
Exec
(
"ALTER TABLE playlist_entries ADD CONSTRAINT fk_playlists_entries FOREIGN KEY (playlist_id) REFERENCES playlists(id) ON UPDATE CASCADE ON DELETE CASCADE "
)
.
Error
;
err
!=
nil
{
return
err
}
return
nil
return
tx
.
Exec
(
"ALTER TABLE import_logs ADD CONSTRAINT fk_import_logs_file FOREIGN KEY (file_id) REFERENCES files(id) ON UPDATE CASCADE ON DELETE CASCADE "
)
.
Error
}
func
(
st
*
Store
)
initDBModel
(
cfg
DBConfig
)
(
err
error
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment