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
8168fb71
Commit
8168fb71
authored
Sep 29, 2023
by
steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update migrator
parent
87ddeb2c
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
136 additions
and
168 deletions
+136
-168
LATEST__SCHEMA.sql
store/mysql/migration/dev/LATEST__SCHEMA.sql
+56
-75
LATEST__SCHEMA.sql
store/mysql/migration/prod/LATEST__SCHEMA.sql
+56
-75
migrator.go
store/mysql/migrator.go
+18
-16
mysql.go
store/mysql/mysql.go
+5
-1
migrator.go
store/sqlite/migrator.go
+1
-1
No files found.
store/mysql/migration/dev/LATEST__SCHEMA.sql
View file @
8168fb71
...
@@ -14,130 +14,111 @@ DROP TABLE IF EXISTS `idp`;
...
@@ -14,130 +14,111 @@ DROP TABLE IF EXISTS `idp`;
-- migration_history
-- migration_history
CREATE
TABLE
`migration_history`
(
CREATE
TABLE
`migration_history`
(
`version`
varchar
(
255
)
NOT
NULL
,
`version`
VARCHAR
(
255
)
NOT
NULL
PRIMARY
KEY
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
PRIMARY
KEY
(
`version`
)
);
);
-- system_setting
-- system_setting
CREATE
TABLE
`system_setting`
(
CREATE
TABLE
`system_setting`
(
`name`
varchar
(
255
)
NOT
NULL
,
`name`
VARCHAR
(
255
)
NOT
NULL
PRIMARY
KEY
,
`value`
text
NOT
NULL
,
`value`
TEXT
NOT
NULL
,
`description`
text
NOT
NULL
,
`description`
TEXT
NOT
NULL
PRIMARY
KEY
(
`name`
)
);
);
-- user
-- user
CREATE
TABLE
`user`
(
CREATE
TABLE
`user`
(
`id`
int
NOT
NULL
AUTO_INCREMENT
,
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`row_status`
varchar
(
255
)
NOT
NULL
DEFAULT
'NORMAL'
,
`row_status`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
'NORMAL'
,
`username`
varchar
(
255
)
NOT
NULL
,
`username`
VARCHAR
(
255
)
NOT
NULL
UNIQUE
,
`role`
varchar
(
255
)
NOT
NULL
DEFAULT
'USER'
,
`role`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
'USER'
,
`email`
varchar
(
255
)
NOT
NULL
DEFAULT
''
,
`email`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
''
,
`nickname`
varchar
(
255
)
NOT
NULL
DEFAULT
''
,
`nickname`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
''
,
`password_hash`
varchar
(
255
)
NOT
NULL
,
`password_hash`
VARCHAR
(
255
)
NOT
NULL
,
`avatar_url`
text
NOT
NULL
,
`avatar_url`
TEXT
NOT
NULL
PRIMARY
KEY
(
`id`
),
UNIQUE
KEY
`username`
(
`username`
),
CONSTRAINT
`user_chk_1`
CHECK
((
`row_status`
in
(
_utf8mb4
'NORMAL'
,
_utf8mb4
'ARCHIVED'
))),
CONSTRAINT
`user_chk_2`
CHECK
((
`role`
in
(
_utf8mb4
'HOST'
,
_utf8mb4
'ADMIN'
,
_utf8mb4
'USER'
)))
);
);
-- user_setting
-- user_setting
CREATE
TABLE
`user_setting`
(
CREATE
TABLE
`user_setting`
(
`user_id`
int
NOT
NULL
,
`user_id`
INT
NOT
NULL
,
`key`
varchar
(
255
)
NOT
NULL
,
`key`
VARCHAR
(
255
)
NOT
NULL
,
`value`
text
NOT
NULL
,
`value`
TEXT
NOT
NULL
,
UNIQUE
KEY
`user_id`
(
`user_id`
,
`key`
)
UNIQUE
(
`user_id`
,
`key`
)
);
);
-- memo
-- memo
CREATE
TABLE
`memo`
(
CREATE
TABLE
`memo`
(
`id`
int
NOT
NULL
AUTO_INCREMENT
,
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`creator_id`
int
NOT
NULL
,
`creator_id`
INT
NOT
NULL
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`row_status`
varchar
(
255
)
NOT
NULL
DEFAULT
'NORMAL'
,
`row_status`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
'NORMAL'
,
`content`
text
NOT
NULL
,
`content`
TEXT
NOT
NULL
,
`visibility`
varchar
(
255
)
NOT
NULL
DEFAULT
'PRIVATE'
,
`visibility`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
'PRIVATE'
PRIMARY
KEY
(
`id`
),
KEY
`creator_id`
(
`creator_id`
),
KEY
`visibility`
(
`visibility`
),
CONSTRAINT
`memo_chk_1`
CHECK
((
`row_status`
in
(
_utf8mb4
'NORMAL'
,
_utf8mb4
'ARCHIVED'
))),
CONSTRAINT
`memo_chk_2`
CHECK
((
`visibility`
in
(
_utf8mb4
'PUBLIC'
,
_utf8mb4
'PROTECTED'
,
_utf8mb4
'PRIVATE'
)))
);
);
-- memo_organizer
-- memo_organizer
CREATE
TABLE
`memo_organizer`
(
CREATE
TABLE
`memo_organizer`
(
`memo_id`
int
NOT
NULL
,
`memo_id`
INT
NOT
NULL
,
`user_id`
int
NOT
NULL
,
`user_id`
INT
NOT
NULL
,
`pinned`
int
NOT
NULL
DEFAULT
'0'
,
`pinned`
INT
NOT
NULL
DEFAULT
'0'
,
UNIQUE
KEY
`memo_id`
(
`memo_id`
,
`user_id`
),
UNIQUE
(
`memo_id`
,
`user_id`
)
CONSTRAINT
`memo_organizer_chk_1`
CHECK
((
`pinned`
in
(
0
,
1
)))
);
);
-- memo_relation
-- memo_relation
CREATE
TABLE
`memo_relation`
(
CREATE
TABLE
`memo_relation`
(
`memo_id`
int
NOT
NULL
,
`memo_id`
INT
NOT
NULL
,
`related_memo_id`
int
NOT
NULL
,
`related_memo_id`
INT
NOT
NULL
,
`type`
varchar
(
256
)
NOT
NULL
,
`type`
VARCHAR
(
256
)
NOT
NULL
,
UNIQUE
KEY
`memo_id`
(
`memo_id`
,
`related_memo_id`
,
`type`
)
UNIQUE
(
`memo_id`
,
`related_memo_id`
,
`type`
)
);
);
-- resource
-- resource
CREATE
TABLE
`resource`
(
CREATE
TABLE
`resource`
(
`id`
int
NOT
NULL
AUTO_INCREMENT
,
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`creator_id`
int
NOT
NULL
,
`creator_id`
INT
NOT
NULL
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`filename`
text
NOT
NULL
,
`filename`
TEXT
NOT
NULL
,
`blob`
blob
,
`blob`
BLOB
,
`external_link`
text
NOT
NULL
,
`external_link`
TEXT
NOT
NULL
,
`type`
varchar
(
255
)
NOT
NULL
DEFAULT
''
,
`type`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
''
,
`size`
int
NOT
NULL
DEFAULT
'0'
,
`size`
INT
NOT
NULL
DEFAULT
'0'
,
`internal_path`
varchar
(
255
)
NOT
NULL
DEFAULT
''
,
`INTernal_path`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
''
,
`memo_id`
int
DEFAULT
NULL
,
`memo_id`
INT
DEFAULT
NULL
PRIMARY
KEY
(
`id`
),
KEY
`creator_id`
(
`creator_id`
),
KEY
`memo_id`
(
`memo_id`
)
);
);
-- tag
-- tag
CREATE
TABLE
`tag`
(
CREATE
TABLE
`tag`
(
`name`
varchar
(
255
)
NOT
NULL
,
`name`
VARCHAR
(
255
)
NOT
NULL
,
`creator_id`
int
NOT
NULL
,
`creator_id`
INT
NOT
NULL
,
UNIQUE
KEY
`name`
(
`name`
,
`creator_id`
)
UNIQUE
(
`name`
,
`creator_id`
)
);
);
-- activity
-- activity
CREATE
TABLE
`activity`
(
CREATE
TABLE
`activity`
(
`id`
int
NOT
NULL
AUTO_INCREMENT
,
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`creator_id`
int
NOT
NULL
,
`creator_id`
INT
NOT
NULL
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`type`
varchar
(
255
)
NOT
NULL
DEFAULT
''
,
`type`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
''
,
`level`
varchar
(
255
)
NOT
NULL
DEFAULT
'INFO'
,
`level`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
'INFO'
,
`payload`
text
NOT
NULL
,
`payload`
TEXT
NOT
NULL
PRIMARY
KEY
(
`id`
),
CONSTRAINT
`activity_chk_1`
CHECK
((
`level`
in
(
_utf8mb4
'INFO'
,
_utf8mb4
'WARN'
,
_utf8mb4
'ERROR'
)))
);
);
-- storage
-- storage
CREATE
TABLE
`storage`
(
CREATE
TABLE
`storage`
(
`id`
int
NOT
NULL
AUTO_INCREMENT
,
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`name`
varchar
(
256
)
NOT
NULL
,
`name`
VARCHAR
(
256
)
NOT
NULL
,
`type`
varchar
(
256
)
NOT
NULL
,
`type`
VARCHAR
(
256
)
NOT
NULL
,
`config`
text
NOT
NULL
,
`config`
TEXT
NOT
NULL
PRIMARY
KEY
(
`id`
)
);
);
-- idp
-- idp
CREATE
TABLE
`idp`
(
CREATE
TABLE
`idp`
(
`id`
int
NOT
NULL
AUTO_INCREMENT
,
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`name`
text
NOT
NULL
,
`name`
TEXT
NOT
NULL
,
`type`
text
NOT
NULL
,
`type`
TEXT
NOT
NULL
,
`identifier_filter`
varchar
(
256
)
NOT
NULL
DEFAULT
''
,
`identifier_filter`
VARCHAR
(
256
)
NOT
NULL
DEFAULT
''
,
`config`
text
NOT
NULL
,
`config`
TEXT
NOT
NULL
PRIMARY
KEY
(
`id`
)
);
);
store/mysql/migration/prod/LATEST__SCHEMA.sql
View file @
8168fb71
...
@@ -14,130 +14,111 @@ DROP TABLE IF EXISTS `idp`;
...
@@ -14,130 +14,111 @@ DROP TABLE IF EXISTS `idp`;
-- migration_history
-- migration_history
CREATE
TABLE
`migration_history`
(
CREATE
TABLE
`migration_history`
(
`version`
varchar
(
255
)
NOT
NULL
,
`version`
VARCHAR
(
255
)
NOT
NULL
PRIMARY
KEY
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
PRIMARY
KEY
(
`version`
)
);
);
-- system_setting
-- system_setting
CREATE
TABLE
`system_setting`
(
CREATE
TABLE
`system_setting`
(
`name`
varchar
(
255
)
NOT
NULL
,
`name`
VARCHAR
(
255
)
NOT
NULL
PRIMARY
KEY
,
`value`
text
NOT
NULL
,
`value`
TEXT
NOT
NULL
,
`description`
text
NOT
NULL
,
`description`
TEXT
NOT
NULL
PRIMARY
KEY
(
`name`
)
);
);
-- user
-- user
CREATE
TABLE
`user`
(
CREATE
TABLE
`user`
(
`id`
int
NOT
NULL
AUTO_INCREMENT
,
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`row_status`
varchar
(
255
)
NOT
NULL
DEFAULT
'NORMAL'
,
`row_status`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
'NORMAL'
,
`username`
varchar
(
255
)
NOT
NULL
,
`username`
VARCHAR
(
255
)
NOT
NULL
UNIQUE
,
`role`
varchar
(
255
)
NOT
NULL
DEFAULT
'USER'
,
`role`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
'USER'
,
`email`
varchar
(
255
)
NOT
NULL
DEFAULT
''
,
`email`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
''
,
`nickname`
varchar
(
255
)
NOT
NULL
DEFAULT
''
,
`nickname`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
''
,
`password_hash`
varchar
(
255
)
NOT
NULL
,
`password_hash`
VARCHAR
(
255
)
NOT
NULL
,
`avatar_url`
text
NOT
NULL
,
`avatar_url`
TEXT
NOT
NULL
PRIMARY
KEY
(
`id`
),
UNIQUE
KEY
`username`
(
`username`
),
CONSTRAINT
`user_chk_1`
CHECK
((
`row_status`
in
(
_utf8mb4
'NORMAL'
,
_utf8mb4
'ARCHIVED'
))),
CONSTRAINT
`user_chk_2`
CHECK
((
`role`
in
(
_utf8mb4
'HOST'
,
_utf8mb4
'ADMIN'
,
_utf8mb4
'USER'
)))
);
);
-- user_setting
-- user_setting
CREATE
TABLE
`user_setting`
(
CREATE
TABLE
`user_setting`
(
`user_id`
int
NOT
NULL
,
`user_id`
INT
NOT
NULL
,
`key`
varchar
(
255
)
NOT
NULL
,
`key`
VARCHAR
(
255
)
NOT
NULL
,
`value`
text
NOT
NULL
,
`value`
TEXT
NOT
NULL
,
UNIQUE
KEY
`user_id`
(
`user_id`
,
`key`
)
UNIQUE
(
`user_id`
,
`key`
)
);
);
-- memo
-- memo
CREATE
TABLE
`memo`
(
CREATE
TABLE
`memo`
(
`id`
int
NOT
NULL
AUTO_INCREMENT
,
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`creator_id`
int
NOT
NULL
,
`creator_id`
INT
NOT
NULL
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`row_status`
varchar
(
255
)
NOT
NULL
DEFAULT
'NORMAL'
,
`row_status`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
'NORMAL'
,
`content`
text
NOT
NULL
,
`content`
TEXT
NOT
NULL
,
`visibility`
varchar
(
255
)
NOT
NULL
DEFAULT
'PRIVATE'
,
`visibility`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
'PRIVATE'
PRIMARY
KEY
(
`id`
),
KEY
`creator_id`
(
`creator_id`
),
KEY
`visibility`
(
`visibility`
),
CONSTRAINT
`memo_chk_1`
CHECK
((
`row_status`
in
(
_utf8mb4
'NORMAL'
,
_utf8mb4
'ARCHIVED'
))),
CONSTRAINT
`memo_chk_2`
CHECK
((
`visibility`
in
(
_utf8mb4
'PUBLIC'
,
_utf8mb4
'PROTECTED'
,
_utf8mb4
'PRIVATE'
)))
);
);
-- memo_organizer
-- memo_organizer
CREATE
TABLE
`memo_organizer`
(
CREATE
TABLE
`memo_organizer`
(
`memo_id`
int
NOT
NULL
,
`memo_id`
INT
NOT
NULL
,
`user_id`
int
NOT
NULL
,
`user_id`
INT
NOT
NULL
,
`pinned`
int
NOT
NULL
DEFAULT
'0'
,
`pinned`
INT
NOT
NULL
DEFAULT
'0'
,
UNIQUE
KEY
`memo_id`
(
`memo_id`
,
`user_id`
),
UNIQUE
(
`memo_id`
,
`user_id`
)
CONSTRAINT
`memo_organizer_chk_1`
CHECK
((
`pinned`
in
(
0
,
1
)))
);
);
-- memo_relation
-- memo_relation
CREATE
TABLE
`memo_relation`
(
CREATE
TABLE
`memo_relation`
(
`memo_id`
int
NOT
NULL
,
`memo_id`
INT
NOT
NULL
,
`related_memo_id`
int
NOT
NULL
,
`related_memo_id`
INT
NOT
NULL
,
`type`
varchar
(
256
)
NOT
NULL
,
`type`
VARCHAR
(
256
)
NOT
NULL
,
UNIQUE
KEY
`memo_id`
(
`memo_id`
,
`related_memo_id`
,
`type`
)
UNIQUE
(
`memo_id`
,
`related_memo_id`
,
`type`
)
);
);
-- resource
-- resource
CREATE
TABLE
`resource`
(
CREATE
TABLE
`resource`
(
`id`
int
NOT
NULL
AUTO_INCREMENT
,
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`creator_id`
int
NOT
NULL
,
`creator_id`
INT
NOT
NULL
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`updated_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`filename`
text
NOT
NULL
,
`filename`
TEXT
NOT
NULL
,
`blob`
blob
,
`blob`
BLOB
,
`external_link`
text
NOT
NULL
,
`external_link`
TEXT
NOT
NULL
,
`type`
varchar
(
255
)
NOT
NULL
DEFAULT
''
,
`type`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
''
,
`size`
int
NOT
NULL
DEFAULT
'0'
,
`size`
INT
NOT
NULL
DEFAULT
'0'
,
`internal_path`
varchar
(
255
)
NOT
NULL
DEFAULT
''
,
`INTernal_path`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
''
,
`memo_id`
int
DEFAULT
NULL
,
`memo_id`
INT
DEFAULT
NULL
PRIMARY
KEY
(
`id`
),
KEY
`creator_id`
(
`creator_id`
),
KEY
`memo_id`
(
`memo_id`
)
);
);
-- tag
-- tag
CREATE
TABLE
`tag`
(
CREATE
TABLE
`tag`
(
`name`
varchar
(
255
)
NOT
NULL
,
`name`
VARCHAR
(
255
)
NOT
NULL
,
`creator_id`
int
NOT
NULL
,
`creator_id`
INT
NOT
NULL
,
UNIQUE
KEY
`name`
(
`name`
,
`creator_id`
)
UNIQUE
(
`name`
,
`creator_id`
)
);
);
-- activity
-- activity
CREATE
TABLE
`activity`
(
CREATE
TABLE
`activity`
(
`id`
int
NOT
NULL
AUTO_INCREMENT
,
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`creator_id`
int
NOT
NULL
,
`creator_id`
INT
NOT
NULL
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`created_ts`
TIMESTAMP
NOT
NULL
DEFAULT
CURRENT_TIMESTAMP
,
`type`
varchar
(
255
)
NOT
NULL
DEFAULT
''
,
`type`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
''
,
`level`
varchar
(
255
)
NOT
NULL
DEFAULT
'INFO'
,
`level`
VARCHAR
(
255
)
NOT
NULL
DEFAULT
'INFO'
,
`payload`
text
NOT
NULL
,
`payload`
TEXT
NOT
NULL
PRIMARY
KEY
(
`id`
),
CONSTRAINT
`activity_chk_1`
CHECK
((
`level`
in
(
_utf8mb4
'INFO'
,
_utf8mb4
'WARN'
,
_utf8mb4
'ERROR'
)))
);
);
-- storage
-- storage
CREATE
TABLE
`storage`
(
CREATE
TABLE
`storage`
(
`id`
int
NOT
NULL
AUTO_INCREMENT
,
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`name`
varchar
(
256
)
NOT
NULL
,
`name`
VARCHAR
(
256
)
NOT
NULL
,
`type`
varchar
(
256
)
NOT
NULL
,
`type`
VARCHAR
(
256
)
NOT
NULL
,
`config`
text
NOT
NULL
,
`config`
TEXT
NOT
NULL
PRIMARY
KEY
(
`id`
)
);
);
-- idp
-- idp
CREATE
TABLE
`idp`
(
CREATE
TABLE
`idp`
(
`id`
int
NOT
NULL
AUTO_INCREMENT
,
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`name`
text
NOT
NULL
,
`name`
TEXT
NOT
NULL
,
`type`
text
NOT
NULL
,
`type`
TEXT
NOT
NULL
,
`identifier_filter`
varchar
(
256
)
NOT
NULL
DEFAULT
''
,
`identifier_filter`
VARCHAR
(
256
)
NOT
NULL
DEFAULT
''
,
`config`
text
NOT
NULL
,
`config`
TEXT
NOT
NULL
PRIMARY
KEY
(
`id`
)
);
);
store/mysql/migrat
e
.go
→
store/mysql/migrat
or
.go
View file @
8168fb71
...
@@ -35,16 +35,10 @@ func (d *Driver) nonProdMigrate(ctx context.Context) error {
...
@@ -35,16 +35,10 @@ func (d *Driver) nonProdMigrate(ctx context.Context) error {
return
errors
.
Errorf
(
"failed to read latest schema file: %s"
,
err
)
return
errors
.
Errorf
(
"failed to read latest schema file: %s"
,
err
)
}
}
for
_
,
stmt
:=
range
strings
.
Split
(
string
(
buf
),
";"
)
{
stmt
:=
string
(
buf
)
stmt
=
strings
.
TrimSpace
(
stmt
)
if
_
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
);
err
!=
nil
{
if
stmt
==
""
{
continue
}
_
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
)
if
err
!=
nil
{
return
errors
.
Errorf
(
"failed to exec SQL %s: %s"
,
stmt
,
err
)
return
errors
.
Errorf
(
"failed to exec SQL %s: %s"
,
stmt
,
err
)
}
}
}
// In demo mode, we should seed the database.
// In demo mode, we should seed the database.
if
d
.
profile
.
Mode
==
"demo"
{
if
d
.
profile
.
Mode
==
"demo"
{
...
@@ -54,17 +48,27 @@ func (d *Driver) nonProdMigrate(ctx context.Context) error {
...
@@ -54,17 +48,27 @@ func (d *Driver) nonProdMigrate(ctx context.Context) error {
}
}
return
nil
return
nil
}
}
func
(
d
*
Driver
)
prodMigrate
(
ctx
context
.
Context
)
error
{
func
(
d
*
Driver
)
prodMigrate
(
ctx
context
.
Context
)
error
{
currentVersion
:=
version
.
GetCurrentVersion
(
d
.
profile
.
Mode
)
currentVersion
:=
version
.
GetCurrentVersion
(
d
.
profile
.
Mode
)
migrationHistoryList
,
err
:=
d
.
FindMigrationHistoryList
(
ctx
,
&
MigrationHistoryFind
{})
migrationHistoryList
,
err
:=
d
.
FindMigrationHistoryList
(
ctx
,
&
MigrationHistoryFind
{})
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to find migration history"
)
return
errors
.
Wrap
(
err
,
"failed to find migration history"
)
}
}
// If there is no migration history, we should apply the latest schema.
if
len
(
migrationHistoryList
)
==
0
{
if
len
(
migrationHistoryList
)
==
0
{
_
,
err
:=
d
.
UpsertMigrationHistory
(
ctx
,
&
MigrationHistoryUpsert
{
buf
,
err
:=
migrationFS
.
ReadFile
(
"migration/prod/"
+
latestSchemaFileName
)
Version
:
currentVersion
,
})
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Errorf
(
"failed to read latest schema file: %s"
,
err
)
}
stmt
:=
string
(
buf
)
if
_
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
);
err
!=
nil
{
return
errors
.
Errorf
(
"failed to exec SQL %s: %s"
,
stmt
,
err
)
}
if
_
,
err
:=
d
.
UpsertMigrationHistory
(
ctx
,
&
MigrationHistoryUpsert
{
Version
:
currentVersion
,
});
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to upsert migration history"
)
return
errors
.
Wrap
(
err
,
"failed to upsert migration history"
)
}
}
return
nil
return
nil
...
@@ -76,7 +80,6 @@ func (d *Driver) prodMigrate(ctx context.Context) error {
...
@@ -76,7 +80,6 @@ func (d *Driver) prodMigrate(ctx context.Context) error {
}
}
sort
.
Sort
(
version
.
SortVersion
(
migrationHistoryVersionList
))
sort
.
Sort
(
version
.
SortVersion
(
migrationHistoryVersionList
))
latestMigrationHistoryVersion
:=
migrationHistoryVersionList
[
len
(
migrationHistoryVersionList
)
-
1
]
latestMigrationHistoryVersion
:=
migrationHistoryVersionList
[
len
(
migrationHistoryVersionList
)
-
1
]
if
!
version
.
IsVersionGreaterThan
(
version
.
GetSchemaVersion
(
currentVersion
),
latestMigrationHistoryVersion
)
{
if
!
version
.
IsVersionGreaterThan
(
version
.
GetSchemaVersion
(
currentVersion
),
latestMigrationHistoryVersion
)
{
return
nil
return
nil
}
}
...
@@ -96,7 +99,7 @@ func (d *Driver) prodMigrate(ctx context.Context) error {
...
@@ -96,7 +99,7 @@ func (d *Driver) prodMigrate(ctx context.Context) error {
}
}
func
(
d
*
Driver
)
applyMigrationForMinorVersion
(
ctx
context
.
Context
,
minorVersion
string
)
error
{
func
(
d
*
Driver
)
applyMigrationForMinorVersion
(
ctx
context
.
Context
,
minorVersion
string
)
error
{
filenames
,
err
:=
fs
.
Glob
(
migrationFS
,
fmt
.
Sprintf
(
"
%s/%s/*.sql"
,
"migration/prod
"
,
minorVersion
))
filenames
,
err
:=
fs
.
Glob
(
migrationFS
,
fmt
.
Sprintf
(
"
migration/prod/%s/*.sql
"
,
minorVersion
))
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to read ddl files"
)
return
errors
.
Wrap
(
err
,
"failed to read ddl files"
)
}
}
...
@@ -131,13 +134,12 @@ func (d *Driver) applyMigrationForMinorVersion(ctx context.Context, minorVersion
...
@@ -131,13 +134,12 @@ func (d *Driver) applyMigrationForMinorVersion(ctx context.Context, minorVersion
var
seedFS
embed
.
FS
var
seedFS
embed
.
FS
func
(
d
*
Driver
)
seed
(
ctx
context
.
Context
)
error
{
func
(
d
*
Driver
)
seed
(
ctx
context
.
Context
)
error
{
filenames
,
err
:=
fs
.
Glob
(
seedFS
,
fmt
.
Sprintf
(
"%s/*.sql"
,
"seed"
)
)
filenames
,
err
:=
fs
.
Glob
(
seedFS
,
"seed/*.sql"
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to read seed files"
)
return
errors
.
Wrap
(
err
,
"failed to read seed files"
)
}
}
sort
.
Strings
(
filenames
)
sort
.
Strings
(
filenames
)
// Loop over all seed files and execute them in order.
// Loop over all seed files and execute them in order.
for
_
,
filename
:=
range
filenames
{
for
_
,
filename
:=
range
filenames
{
buf
,
err
:=
seedFS
.
ReadFile
(
filename
)
buf
,
err
:=
seedFS
.
ReadFile
(
filename
)
...
...
store/mysql/mysql.go
View file @
8168fb71
...
@@ -3,6 +3,7 @@ package mysql
...
@@ -3,6 +3,7 @@ package mysql
import
(
import
(
"context"
"context"
"database/sql"
"database/sql"
"fmt"
"github.com/pkg/errors"
"github.com/pkg/errors"
...
@@ -16,7 +17,10 @@ type Driver struct {
...
@@ -16,7 +17,10 @@ type Driver struct {
}
}
func
NewDriver
(
profile
*
profile
.
Profile
)
(
store
.
Driver
,
error
)
{
func
NewDriver
(
profile
*
profile
.
Profile
)
(
store
.
Driver
,
error
)
{
db
,
err
:=
sql
.
Open
(
"mysql"
,
profile
.
DSN
)
// Open MySQL connection with parameter.
// multiStatements=true is required for migration.
// See more in: https://github.com/go-sql-driver/mysql#multistatements
db
,
err
:=
sql
.
Open
(
"mysql"
,
fmt
.
Sprintf
(
"%s?multiStatements=true"
,
profile
.
DSN
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
errors
.
Wrapf
(
err
,
"failed to open db: %s"
,
profile
.
DSN
)
return
nil
,
errors
.
Wrapf
(
err
,
"failed to open db: %s"
,
profile
.
DSN
)
}
}
...
...
store/sqlite/migrat
e
.go
→
store/sqlite/migrat
or
.go
View file @
8168fb71
...
@@ -117,7 +117,7 @@ func (d *Driver) applyLatestSchema(ctx context.Context) error {
...
@@ -117,7 +117,7 @@ func (d *Driver) applyLatestSchema(ctx context.Context) error {
if
d
.
profile
.
Mode
==
"prod"
{
if
d
.
profile
.
Mode
==
"prod"
{
schemaMode
=
"prod"
schemaMode
=
"prod"
}
}
latestSchemaPath
:=
fmt
.
Sprintf
(
"
%s/%s/%s"
,
"migration
"
,
schemaMode
,
latestSchemaFileName
)
latestSchemaPath
:=
fmt
.
Sprintf
(
"
migration/%s/%s
"
,
schemaMode
,
latestSchemaFileName
)
buf
,
err
:=
migrationFS
.
ReadFile
(
latestSchemaPath
)
buf
,
err
:=
migrationFS
.
ReadFile
(
latestSchemaPath
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrapf
(
err
,
"failed to read latest schema %q"
,
latestSchemaPath
)
return
errors
.
Wrapf
(
err
,
"failed to read latest schema %q"
,
latestSchemaPath
)
...
...
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