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
e8e6f8de
Verified
Commit
e8e6f8de
authored
3 weeks ago
by
Ernesto Rico Schmidt
Browse files
Options
Downloads
Patches
Plain Diff
feat: move constraints -> type definitions
parent
066862ff
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
store/migrations.go
+1
-16
1 addition, 16 deletions
store/migrations.go
store/types.go
+2
-2
2 additions, 2 deletions
store/types.go
with
3 additions
and
18 deletions
store/migrations.go
+
1
−
16
View file @
e8e6f8de
...
...
@@ -202,22 +202,7 @@ var (
)
func
initialMigration
(
tx
*
gorm
.
DB
)
(
err
error
)
{
if
err
=
tx
.
AutoMigrate
(
&
Show
{},
&
File
{},
&
ImportLog
{});
err
!=
nil
{
return
err
}
// replace the constraints created
if
err
=
tx
.
Exec
(
"ALTER TABLE files DROP CONSTRAINT fk_files_show"
)
.
Error
;
err
!=
nil
{
return
err
}
if
err
=
tx
.
Exec
(
"ALTER TABLE files ADD CONSTRAINT fk_files_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 import_logs DROP CONSTRAINT fk_import_logs_file"
)
.
Error
;
err
!=
nil
{
return
err
}
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
return
tx
.
AutoMigrate
(
&
Show
{},
&
File
{},
&
ImportLog
{})
}
func
(
st
*
Store
)
initDBModel
(
cfg
DBConfig
)
(
err
error
)
{
...
...
This diff is collapsed.
Click to expand it.
store/types.go
+
2
−
2
View file @
e8e6f8de
...
...
@@ -159,7 +159,7 @@ type File struct {
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"`
...
...
@@ -170,7 +170,7 @@ type File struct {
type
ImportLog
struct
{
ID
uint64
`gorm:"primaryKey"`
File
File
`gorm:"associationAutoUpdate:false;associationAutoCreate:false"`
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"`
...
...
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