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
cfa4151c
Commit
cfa4151c
authored
Jul 25, 2022
by
boojack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update migration folder
parent
3d33b5d5
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
144 additions
and
3 deletions
+144
-3
db.go
store/db/db.go
+3
-3
LATEST__SCHEMA.sql
store/db/migration/dev/LATEST__SCHEMA.sql
+0
-0
00__user_role.sql
store/db/migration/prod/0.2/00__user_role.sql
+0
-0
01__memo_visibility.sql
store/db/migration/prod/0.2/01__memo_visibility.sql
+0
-0
00__memo_visibility_protected.sql
...e/db/migration/prod/0.3/00__memo_visibility_protected.sql
+0
-0
LATEST__SCHEMA.sql
store/db/migration/prod/LATEST__SCHEMA.sql
+141
-0
No files found.
store/db/db.go
View file @
cfa4151c
...
...
@@ -128,7 +128,7 @@ const (
)
func
(
db
*
DB
)
applyLatestSchema
()
error
{
latestSchemaPath
:=
fmt
.
Sprintf
(
"%s/%s
"
,
"migration"
,
latestSchemaFileName
)
latestSchemaPath
:=
fmt
.
Sprintf
(
"%s/%s
/%s"
,
"migration"
,
db
.
profile
.
Mode
,
latestSchemaFileName
)
buf
,
err
:=
migrationFS
.
ReadFile
(
latestSchemaPath
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"failed to read latest schema %q, error %w"
,
latestSchemaPath
,
err
)
...
...
@@ -141,7 +141,7 @@ func (db *DB) applyLatestSchema() error {
}
func
(
db
*
DB
)
applyMigrationForMinorVersion
(
minorVersion
string
)
error
{
filenames
,
err
:=
fs
.
Glob
(
migrationFS
,
fmt
.
Sprintf
(
"%s/%s/*.sql"
,
"migration"
,
minorVersion
))
filenames
,
err
:=
fs
.
Glob
(
migrationFS
,
fmt
.
Sprintf
(
"%s/%s/*.sql"
,
"migration
/prod
"
,
minorVersion
))
if
err
!=
nil
{
return
err
}
...
...
@@ -210,7 +210,7 @@ func (db *DB) execute(stmt string) error {
}
// minorDirRegexp is a regular expression for minor version directory.
var
minorDirRegexp
=
regexp
.
MustCompile
(
`^migration/[0-9]+\.[0-9]+$`
)
var
minorDirRegexp
=
regexp
.
MustCompile
(
`^migration/
prod/
[0-9]+\.[0-9]+$`
)
func
getMinorVersionList
()
[]
string
{
minorVersionList
:=
[]
string
{}
...
...
store/db/migration/LATEST__SCHEMA.sql
→
store/db/migration/
dev/
LATEST__SCHEMA.sql
View file @
cfa4151c
File moved
store/db/migration/0.2/00__user_role.sql
→
store/db/migration/
prod/
0.2/00__user_role.sql
View file @
cfa4151c
File moved
store/db/migration/0.2/01__memo_visibility.sql
→
store/db/migration/
prod/
0.2/01__memo_visibility.sql
View file @
cfa4151c
File moved
store/db/migration/0.3/00__memo_visibility_protected.sql
→
store/db/migration/
prod/
0.3/00__memo_visibility_protected.sql
View file @
cfa4151c
File moved
store/db/migration/prod/LATEST__SCHEMA.sql
0 → 100644
View file @
cfa4151c
-- drop all tables
DROP
TABLE
IF
EXISTS
`memo_organizer`
;
DROP
TABLE
IF
EXISTS
`memo`
;
DROP
TABLE
IF
EXISTS
`shortcut`
;
DROP
TABLE
IF
EXISTS
`resource`
;
DROP
TABLE
IF
EXISTS
`user`
;
-- user
CREATE
TABLE
user
(
id
INTEGER
PRIMARY
KEY
AUTOINCREMENT
,
created_ts
BIGINT
NOT
NULL
DEFAULT
(
strftime
(
'%s'
,
'now'
)),
updated_ts
BIGINT
NOT
NULL
DEFAULT
(
strftime
(
'%s'
,
'now'
)),
-- allowed row status are 'NORMAL', 'ARCHIVED'.
row_status
TEXT
NOT
NULL
CHECK
(
row_status
IN
(
'NORMAL'
,
'ARCHIVED'
))
DEFAULT
'NORMAL'
,
email
TEXT
NOT
NULL
UNIQUE
,
role
TEXT
NOT
NULL
CHECK
(
role
IN
(
'HOST'
,
'USER'
))
DEFAULT
'USER'
,
name
TEXT
NOT
NULL
,
password_hash
TEXT
NOT
NULL
,
open_id
TEXT
NOT
NULL
UNIQUE
);
INSERT
INTO
sqlite_sequence
(
name
,
seq
)
VALUES
(
'user'
,
100
);
CREATE
TRIGGER
IF
NOT
EXISTS
`trigger_update_user_modification_time`
AFTER
UPDATE
ON
`user`
FOR
EACH
ROW
BEGIN
UPDATE
`user`
SET
updated_ts
=
(
strftime
(
'%s'
,
'now'
))
WHERE
rowid
=
old
.
rowid
;
END
;
-- memo
CREATE
TABLE
memo
(
id
INTEGER
PRIMARY
KEY
AUTOINCREMENT
,
creator_id
INTEGER
NOT
NULL
,
created_ts
BIGINT
NOT
NULL
DEFAULT
(
strftime
(
'%s'
,
'now'
)),
updated_ts
BIGINT
NOT
NULL
DEFAULT
(
strftime
(
'%s'
,
'now'
)),
row_status
TEXT
NOT
NULL
CHECK
(
row_status
IN
(
'NORMAL'
,
'ARCHIVED'
))
DEFAULT
'NORMAL'
,
content
TEXT
NOT
NULL
DEFAULT
''
,
visibility
TEXT
NOT
NULL
CHECK
(
visibility
IN
(
'PUBLIC'
,
'PROTECTED'
,
'PRIVATE'
))
DEFAULT
'PRIVATE'
,
FOREIGN
KEY
(
creator_id
)
REFERENCES
user
(
id
)
ON
DELETE
CASCADE
);
INSERT
INTO
sqlite_sequence
(
name
,
seq
)
VALUES
(
'memo'
,
1000
);
CREATE
TRIGGER
IF
NOT
EXISTS
`trigger_update_memo_modification_time`
AFTER
UPDATE
ON
`memo`
FOR
EACH
ROW
BEGIN
UPDATE
`memo`
SET
updated_ts
=
(
strftime
(
'%s'
,
'now'
))
WHERE
rowid
=
old
.
rowid
;
END
;
-- memo_organizer
CREATE
TABLE
memo_organizer
(
id
INTEGER
PRIMARY
KEY
AUTOINCREMENT
,
memo_id
INTEGER
NOT
NULL
,
user_id
INTEGER
NOT
NULL
,
pinned
INTEGER
NOT
NULL
CHECK
(
pinned
IN
(
0
,
1
))
DEFAULT
0
,
FOREIGN
KEY
(
memo_id
)
REFERENCES
memo
(
id
)
ON
DELETE
CASCADE
,
FOREIGN
KEY
(
user_id
)
REFERENCES
user
(
id
)
ON
DELETE
CASCADE
,
UNIQUE
(
memo_id
,
user_id
)
);
INSERT
INTO
sqlite_sequence
(
name
,
seq
)
VALUES
(
'memo_organizer'
,
1000
);
-- shortcut
CREATE
TABLE
shortcut
(
id
INTEGER
PRIMARY
KEY
AUTOINCREMENT
,
creator_id
INTEGER
NOT
NULL
,
created_ts
BIGINT
NOT
NULL
DEFAULT
(
strftime
(
'%s'
,
'now'
)),
updated_ts
BIGINT
NOT
NULL
DEFAULT
(
strftime
(
'%s'
,
'now'
)),
row_status
TEXT
NOT
NULL
CHECK
(
row_status
IN
(
'NORMAL'
,
'ARCHIVED'
))
DEFAULT
'NORMAL'
,
title
TEXT
NOT
NULL
DEFAULT
''
,
payload
TEXT
NOT
NULL
DEFAULT
'{}'
,
FOREIGN
KEY
(
creator_id
)
REFERENCES
user
(
id
)
ON
DELETE
CASCADE
);
INSERT
INTO
sqlite_sequence
(
name
,
seq
)
VALUES
(
'shortcut'
,
10000
);
CREATE
TRIGGER
IF
NOT
EXISTS
`trigger_update_shortcut_modification_time`
AFTER
UPDATE
ON
`shortcut`
FOR
EACH
ROW
BEGIN
UPDATE
`shortcut`
SET
updated_ts
=
(
strftime
(
'%s'
,
'now'
))
WHERE
rowid
=
old
.
rowid
;
END
;
-- resource
CREATE
TABLE
resource
(
id
INTEGER
PRIMARY
KEY
AUTOINCREMENT
,
creator_id
INTEGER
NOT
NULL
,
created_ts
BIGINT
NOT
NULL
DEFAULT
(
strftime
(
'%s'
,
'now'
)),
updated_ts
BIGINT
NOT
NULL
DEFAULT
(
strftime
(
'%s'
,
'now'
)),
filename
TEXT
NOT
NULL
DEFAULT
''
,
blob
BLOB
NOT
NULL
,
type
TEXT
NOT
NULL
DEFAULT
''
,
size
INTEGER
NOT
NULL
DEFAULT
0
,
FOREIGN
KEY
(
creator_id
)
REFERENCES
user
(
id
)
ON
DELETE
CASCADE
);
INSERT
INTO
sqlite_sequence
(
name
,
seq
)
VALUES
(
'resource'
,
10000
);
CREATE
TRIGGER
IF
NOT
EXISTS
`trigger_update_resource_modification_time`
AFTER
UPDATE
ON
`resource`
FOR
EACH
ROW
BEGIN
UPDATE
`resource`
SET
updated_ts
=
(
strftime
(
'%s'
,
'now'
))
WHERE
rowid
=
old
.
rowid
;
END
;
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