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
ffe10732
Unverified
Commit
ffe10732
authored
Feb 19, 2023
by
boojack
Committed by
GitHub
Feb 19, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: schema path for demo mode (#1124)
parent
afaaec84
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
3 deletions
+7
-3
profile.go
server/profile/profile.go
+1
-1
db.go
store/db/db.go
+6
-2
No files found.
server/profile/profile.go
View file @
ffe10732
...
@@ -52,7 +52,7 @@ func GetProfile() (*Profile, error) {
...
@@ -52,7 +52,7 @@ func GetProfile() (*Profile, error) {
flag
.
StringVar
(
&
profile
.
Data
,
"data"
,
""
,
"data directory"
)
flag
.
StringVar
(
&
profile
.
Data
,
"data"
,
""
,
"data directory"
)
flag
.
Parse
()
flag
.
Parse
()
if
profile
.
Mode
!=
"de
v"
&&
profile
.
Mode
!=
"prod"
&&
profile
.
Mode
!=
"demo
"
{
if
profile
.
Mode
!=
"de
mo"
&&
profile
.
Mode
!=
"dev"
&&
profile
.
Mode
!=
"prod
"
{
profile
.
Mode
=
"demo"
profile
.
Mode
=
"demo"
}
}
...
...
store/db/db.go
View file @
ffe10732
...
@@ -111,7 +111,7 @@ func (db *DB) Open(ctx context.Context) (err error) {
...
@@ -111,7 +111,7 @@ func (db *DB) Open(ctx context.Context) (err error) {
}
}
}
}
}
else
{
}
else
{
// In non-prod mode, we should migrate the database.
// In non-prod mode, we should
always
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
)
{
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
)
...
@@ -133,7 +133,11 @@ const (
...
@@ -133,7 +133,11 @@ const (
)
)
func
(
db
*
DB
)
applyLatestSchema
(
ctx
context
.
Context
)
error
{
func
(
db
*
DB
)
applyLatestSchema
(
ctx
context
.
Context
)
error
{
latestSchemaPath
:=
fmt
.
Sprintf
(
"%s/%s/%s"
,
"migration"
,
db
.
profile
.
Mode
,
latestSchemaFileName
)
schemaMode
:=
"dev"
if
db
.
profile
.
Mode
==
"prod"
{
schemaMode
=
"prod"
}
latestSchemaPath
:=
fmt
.
Sprintf
(
"%s/%s/%s"
,
"migration"
,
schemaMode
,
latestSchemaFileName
)
buf
,
err
:=
migrationFS
.
ReadFile
(
latestSchemaPath
)
buf
,
err
:=
migrationFS
.
ReadFile
(
latestSchemaPath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to read latest schema %q, error %w"
,
latestSchemaPath
,
err
)
return
fmt
.
Errorf
(
"failed to read latest schema %q, error %w"
,
latestSchemaPath
,
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