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
c45a3ace
Verified
Commit
c45a3ace
authored
3 weeks ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
feat: replace migrations with a single one
parent
e8e6f8de
No related branches found
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
+15
-141
15 additions, 141 deletions
store/migrations.go
with
15 additions
and
141 deletions
store/migrations.go
+
15
−
141
View file @
c45a3ace
...
...
@@ -20,88 +20,26 @@ package store
import
(
"errors"
"time"
"github.com/go-gormigrate/gormigrate/v2"
"gorm.io/gorm"
"time"
)
var
(
dbMigrations
=
[]
*
gormigrate
.
Migration
{
{
ID
:
"201903131716"
,
Migrate
:
func
(
tx
*
gorm
.
DB
)
error
{
return
nil
},
Rollback
:
func
(
tx
*
gorm
.
DB
)
error
{
return
nil
},
},
{
ID
:
"201905291602"
,
ID
:
"202502171717"
,
Migrate
:
func
(
tx
*
gorm
.
DB
)
error
{
type
Import
struct
{
State
ImportState
`json:"state"`
Error
string
`json:"error,omitempty"`
}
type
FileSource
struct
{
URI
string
`json:"uri" gorm:"size:1024"`
Hash
string
`json:"hash"`
Import
Import
`json:"import" gorm:"embedded;embeddedPrefix:import__"`
}
type
FileMetadata
struct
{
Artist
string
`json:"artist,omitempty" gorm:"index"`
Title
string
`json:"title,omitempty" gorm:"index"`
Album
string
`json:"album,omitempty" gorm:"index"`
}
type
File
struct
{
ID
uint64
`json:"id" gorm:"primaryKey"`
CreatedAt
time
.
Time
`json:"created"`
UpdatedAt
time
.
Time
`json:"updated"`
ShowName
string
`json:"show" gorm:"not null;index"`
Show
Show
`json:"-" gorm:"associationForeignKey:Name"`
Source
FileSource
`json:"source" gorm:"embedded;embeddedPrefix:source__"`
Metadata
FileMetadata
`json:"metadata" gorm:"embedded;embeddedPrefix:metadata__"`
Size
uint64
`json:"size"`
Duration
time
.
Duration
`json:"duration"`
}
return
tx
.
AutoMigrate
(
&
File
{})
},
Rollback
:
func
(
tx
*
gorm
.
DB
)
error
{
return
tx
.
Migrator
()
.
DropColumn
(
&
File
{},
"source__import__error"
)
},
},
{
ID
:
"201906010144"
,
Migrate
:
func
(
tx
*
gorm
.
DB
)
error
{
type
ImportLog
struct
{
ID
uint64
`gorm:"primaryKey"`
File
File
`gorm:"associationAutoUpdate:false;associationAutoCreate:false"`
FileID
uint64
`gorm:"not null;index;uniqueIndex:unique_import_log_step"`
ImportStep
string
`gorm:"not null;index;uniqueIndex:unique_import_log_step"`
Encoded
[]
byte
}
return
tx
.
AutoMigrate
(
&
ImportLog
{})
},
Rollback
:
func
(
tx
*
gorm
.
DB
)
error
{
return
tx
.
Migrator
()
.
DropConstraint
(
&
ImportLog
{},
"file_id"
)
},
},
{
ID
:
"201908150104"
,
Migrate
:
func
(
tx
*
gorm
.
DB
)
error
{
type
Import
struct
{
State
ImportState
`json:"state"`
Error
string
`json:"error,omitempty"`
type
Show
struct
{
ID
uint64
`json:"id" gorm:"primaryKey"`
CreatedAt
time
.
Time
`json:"created"`
UpdatedAt
time
.
Time
`json:"updated"`
}
type
FileSource
struct
{
URI
string
`json:"uri" gorm:"size:1024"`
Hash
string
`json:"hash"`
Import
Import
`json:"import" gorm:"embedded;embeddedPrefix:import__"`
}
type
FileMetadata
struct
{
Artist
string
`json:"artist,omitempty" gorm:"index"`
Title
string
`json:"title,omitempty" gorm:"index"`
...
...
@@ -109,93 +47,29 @@ var (
Organization
string
`json:"organization,omitempty" gorm:"index"`
ISRC
string
`json:"isrc,omitempty" gorm:"index"`
}
type
File
struct
{
ID
uint64
`json:"id" gorm:"primaryKey"`
CreatedAt
time
.
Time
`json:"created"`
UpdatedAt
time
.
Time
`json:"updated"`
ShowName
string
`json:"show" gorm:"not null;index"`
Show
Show
`json:"-" gorm:"associationForeignKey:Name"`
Source
FileSource
`json:"source" gorm:"embedded;embeddedPrefix:source__"`
Metadata
FileMetadata
`json:"metadata" gorm:"embedded;embeddedPrefix:metadata__"`
Size
uint64
`json:"size"`
Duration
time
.
Duration
`json:"duration"`
}
return
tx
.
AutoMigrate
(
&
File
{})
},
Rollback
:
func
(
tx
*
gorm
.
DB
)
error
{
if
err
:=
tx
.
Migrator
()
.
DropColumn
(
&
File
{},
"metadata__organization"
);
err
!=
nil
{
return
err
}
return
tx
.
Migrator
()
.
DropColumn
(
&
File
{},
"metadata__isrc"
)
},
},
{
ID
:
"202309141500"
,
Migrate
:
func
(
tx
*
gorm
.
DB
)
error
{
type
File
struct
{
ID
uint64
`json:"id" gorm:"primaryKey"`
CreatedAt
time
.
Time
`json:"created"`
UpdatedAt
time
.
Time
`json:"updated"`
ShowName
string
`json:"show" gorm:"not null;index"`
Show
Show
`json:"-" gorm:"associationForeignKey:Name"`
Source
FileSource
`json:"source" gorm:"embedded;embeddedPrefix:source__"`
Metadata
FileMetadata
`json:"metadata" gorm:"embedded;embeddedPrefix:metadata__"`
Size
uint64
`json:"size"`
Duration
float64
`json:"duration"`
}
return
tx
.
Migrator
()
.
AlterColumn
(
&
File
{},
"duration"
)
},
Rollback
:
func
(
tx
*
gorm
.
DB
)
error
{
type
File
struct
{
ID
uint64
`json:"id" gorm:"primaryKey"`
CreatedAt
time
.
Time
`json:"created"`
UpdatedAt
time
.
Time
`json:"updated"`
ShowName
string
`json:"show" gorm:"not null;index"`
Show
Show
`json:"-" gorm:"associationForeignKey:Name"`
Source
FileSource
`json:"source" gorm:"embedded;embeddedPrefix:source__"`
Metadata
FileMetadata
`json:"metadata" gorm:"embedded;embeddedPrefix:metadata__"`
Size
uint64
`json:"size"`
Duration
time
.
Duration
`json:"duration"`
}
return
tx
.
Migrator
()
.
AlterColumn
(
&
File
{},
"duration"
)
},
},
{
ID
:
"202312011500"
,
Migrate
:
func
(
tx
*
gorm
.
DB
)
error
{
type
Show
struct
{
ID
uint64
`json:"id" gorm:"primaryKey"`
CreatedAt
time
.
Time
`json:"created"`
UpdatedAt
time
.
Time
`json:"updated"`
}
type
File
struct
{
ID
uint64
`json:"id" gorm:"primaryKey"`
CreatedAt
time
.
Time
`json:"created"`
UpdatedAt
time
.
Time
`json:"updated"`
ShowID
uint64
`json:"showId" gorm:"not null;index"`
Show
Show
`json:"-" gorm:"associationForeignKey:ID"`
Show
Show
`json:"-" gorm:"associationForeignKey:ID
;constraint:OnUpdate:CASCADE,OnDelete:CASCADE
"`
Source
FileSource
`json:"source" gorm:"embedded;embeddedPrefix:source__"`
Metadata
FileMetadata
`json:"metadata" gorm:"embedded;embeddedPrefix:metadata__"`
Size
uint64
`json:"size"`
Duration
float64
`json:"duration"`
}
if
err
:=
tx
.
Migrator
()
.
DropConstraint
(
&
File
{},
"show_name"
);
err
!=
nil
{
return
err
type
ImportLog
struct
{
ID
uint64
`gorm:"primaryKey"`
File
File
`gorm:"associationAutoUpdate:false;associationAutoCreate:false;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
FileID
uint64
`gorm:"not null;index;uniqueIndex:unique_import_log_step"`
ImportStep
string
`gorm:"not null;index;uniqueIndex:unique_import_log_step"`
Encoded
[]
byte
`gorm:"size:-1"`
}
return
tx
.
Auto
Migrate
(
&
Show
{},
&
File
{})
return
tx
.
Migrat
or
()
.
CreateTabl
e
(
&
Show
{},
&
File
{}
,
&
ImportLog
{}
)
},
Rollback
:
func
(
tx
*
gorm
.
DB
)
error
{
if
err
:=
tx
.
Migrator
()
.
DropColumn
(
&
Show
{},
"id"
);
err
!=
nil
{
return
err
}
return
tx
.
Migrator
()
.
DropColumn
(
&
File
{},
"show_id"
)
return
tx
.
Migrator
()
.
DropTable
(
"shows"
,
"files"
,
"import_logs"
)
},
},
}
...
...
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