Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
6a3b052f
Commit
6a3b052f
authored
Oct 03, 2022
by
steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: don't clean data in dev mode
parent
222c7925
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
9 deletions
+9
-9
db.go
store/db/db.go
+9
-9
No files found.
store/db/db.go
View file @
6a3b052f
...
@@ -51,22 +51,22 @@ func (db *DB) Open(ctx context.Context) (err error) {
...
@@ -51,22 +51,22 @@ func (db *DB) Open(ctx context.Context) (err error) {
db
.
Db
=
sqlDB
db
.
Db
=
sqlDB
// If mode is dev, we should migrate and seed the database.
// If mode is dev, we should migrate and seed the database.
if
db
.
profile
.
Mode
==
"dev"
{
if
db
.
profile
.
Mode
==
"dev"
{
if
_
,
err
:=
os
.
Stat
(
db
.
profile
.
DSN
);
errors
.
Is
(
err
,
os
.
ErrNotExist
)
{
if
err
:=
db
.
applyLatestSchema
(
ctx
);
err
!=
nil
{
if
err
:=
db
.
applyLatestSchema
(
ctx
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to apply latest schema: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to apply latest schema: %w"
,
err
)
}
}
if
err
:=
db
.
seed
(
ctx
);
err
!=
nil
{
if
err
:=
db
.
seed
(
ctx
);
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to seed: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to seed: %w"
,
err
)
}
}
}
}
else
{
}
else
{
// If db file not exists, we should migrate the database.
// If db file not exists, we should migrate the database.
if
_
,
err
:=
os
.
Stat
(
db
.
profile
.
DSN
);
errors
.
Is
(
err
,
os
.
ErrNotExist
)
{
if
_
,
err
:=
os
.
Stat
(
db
.
profile
.
DSN
);
errors
.
Is
(
err
,
os
.
ErrNotExist
)
{
err
:=
db
.
applyLatestSchema
(
ctx
)
if
err
:=
db
.
applyLatestSchema
(
ctx
);
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to apply latest schema: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to apply latest schema: %w"
,
err
)
}
}
}
else
{
}
else
{
err
:=
db
.
createMigrationHistoryTable
(
ctx
)
if
err
:=
db
.
createMigrationHistoryTable
(
ctx
);
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to create migration_history table: %w"
,
err
)
return
fmt
.
Errorf
(
"failed to create migration_history table: %w"
,
err
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment