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
e1645177
Commit
e1645177
authored
Mar 19, 2026
by
memoclaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
test: remove raw SQL migration backfill test setup
parent
f759b416
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
118 deletions
+2
-118
containers.go
store/test/containers.go
+2
-1
migrator_test.go
store/test/migrator_test.go
+0
-117
No files found.
store/test/containers.go
View file @
e1645177
...
@@ -289,9 +289,10 @@ func StartMemosContainer(ctx context.Context, cfg MemosContainerConfig) (testcon
...
@@ -289,9 +289,10 @@ func StartMemosContainer(ctx context.Context, cfg MemosContainerConfig) (testcon
if
os
.
Getenv
(
"MEMOS_TEST_IMAGE_BUILT"
)
==
"1"
{
if
os
.
Getenv
(
"MEMOS_TEST_IMAGE_BUILT"
)
==
"1"
{
req
.
Image
=
"memos-test:local"
req
.
Image
=
"memos-test:local"
}
else
{
}
else
{
req
.
Image
=
""
req
.
FromDockerfile
=
testcontainers
.
FromDockerfile
{
req
.
FromDockerfile
=
testcontainers
.
FromDockerfile
{
Context
:
"../../"
,
Context
:
"../../"
,
Dockerfile
:
"Dockerfile"
,
Dockerfile
:
"
scripts/
Dockerfile"
,
}
}
}
}
}
}
...
...
store/test/migrator_test.go
View file @
e1645177
...
@@ -7,10 +7,8 @@ import (
...
@@ -7,10 +7,8 @@ import (
"testing"
"testing"
"time"
"time"
"github.com/pkg/errors"
"github.com/stretchr/testify/require"
"github.com/stretchr/testify/require"
storepb
"github.com/usememos/memos/proto/gen/store"
"github.com/usememos/memos/store"
"github.com/usememos/memos/store"
)
)
...
@@ -89,58 +87,6 @@ func TestMigrationWithData(t *testing.T) {
...
@@ -89,58 +87,6 @@ func TestMigrationWithData(t *testing.T) {
require
.
Equal
(
t
,
"Data before migration re-run"
,
memo
.
Content
,
"memo content should be preserved"
)
require
.
Equal
(
t
,
"Data before migration re-run"
,
memo
.
Content
,
"memo content should be preserved"
)
}
}
func
TestMigrationBackfillsInboxMemoCommentPayload
(
t
*
testing
.
T
)
{
t
.
Parallel
()
ctx
:=
context
.
Background
()
ts
:=
NewTestingStore
(
ctx
,
t
)
user
,
err
:=
createTestingHostUser
(
ctx
,
ts
)
require
.
NoError
(
t
,
err
)
commentMemo
,
err
:=
ts
.
CreateMemo
(
ctx
,
&
store
.
Memo
{
UID
:
"migration-comment-memo"
,
CreatorID
:
user
.
ID
,
Content
:
"Comment memo"
,
Visibility
:
store
.
Public
,
})
require
.
NoError
(
t
,
err
)
relatedMemo
,
err
:=
ts
.
CreateMemo
(
ctx
,
&
store
.
Memo
{
UID
:
"migration-related-memo"
,
CreatorID
:
user
.
ID
,
Content
:
"Related memo"
,
Visibility
:
store
.
Public
,
})
require
.
NoError
(
t
,
err
)
driver
:=
getDriverFromEnv
()
require
.
NoError
(
t
,
createLegacyActivityTable
(
ctx
,
ts
,
driver
))
require
.
NoError
(
t
,
insertLegacyInboxActivity
(
ctx
,
ts
,
driver
,
user
.
ID
,
commentMemo
.
ID
,
relatedMemo
.
ID
))
_
,
err
=
ts
.
UpsertInstanceSetting
(
ctx
,
&
storepb
.
InstanceSetting
{
Key
:
storepb
.
InstanceSettingKey_BASIC
,
Value
:
&
storepb
.
InstanceSetting_BasicSetting
{
BasicSetting
:
&
storepb
.
InstanceBasicSetting
{
SchemaVersion
:
"0.27.2"
,
},
},
})
require
.
NoError
(
t
,
err
)
err
=
ts
.
Migrate
(
ctx
)
require
.
NoError
(
t
,
err
)
messageType
:=
storepb
.
InboxMessage_MEMO_COMMENT
inboxes
,
err
:=
ts
.
ListInboxes
(
ctx
,
&
store
.
FindInbox
{
ReceiverID
:
&
user
.
ID
,
MessageType
:
&
messageType
,
})
require
.
NoError
(
t
,
err
)
require
.
Len
(
t
,
inboxes
,
1
)
require
.
NotNil
(
t
,
inboxes
[
0
]
.
Message
)
require
.
NotNil
(
t
,
inboxes
[
0
]
.
Message
.
GetMemoComment
())
require
.
Equal
(
t
,
commentMemo
.
ID
,
inboxes
[
0
]
.
Message
.
GetMemoComment
()
.
MemoId
)
require
.
Equal
(
t
,
relatedMemo
.
ID
,
inboxes
[
0
]
.
Message
.
GetMemoComment
()
.
RelatedMemoId
)
}
// TestMigrationMultipleReRuns verifies that migration is idempotent
// TestMigrationMultipleReRuns verifies that migration is idempotent
// even when run multiple times in succession.
// even when run multiple times in succession.
func
TestMigrationMultipleReRuns
(
t
*
testing
.
T
)
{
func
TestMigrationMultipleReRuns
(
t
*
testing
.
T
)
{
...
@@ -165,69 +111,6 @@ func TestMigrationMultipleReRuns(t *testing.T) {
...
@@ -165,69 +111,6 @@ func TestMigrationMultipleReRuns(t *testing.T) {
require
.
Equal
(
t
,
initialVersion
,
finalVersion
,
"version should remain unchanged after multiple re-runs"
)
require
.
Equal
(
t
,
initialVersion
,
finalVersion
,
"version should remain unchanged after multiple re-runs"
)
}
}
func
createLegacyActivityTable
(
ctx
context
.
Context
,
ts
*
store
.
Store
,
driver
string
)
error
{
var
stmt
string
switch
driver
{
case
"sqlite"
:
stmt
=
`CREATE TABLE activity (
id INTEGER PRIMARY KEY AUTOINCREMENT,
creator_id INTEGER NOT NULL,
created_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
type TEXT NOT NULL DEFAULT '',
level TEXT NOT NULL DEFAULT 'INFO',
payload TEXT NOT NULL DEFAULT '{}'
);`
case
"mysql"
:
stmt
=
`CREATE TABLE activity (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
creator_id INT NOT NULL,
created_ts TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
type VARCHAR(256) NOT NULL DEFAULT '',
level VARCHAR(256) NOT NULL DEFAULT 'INFO',
payload TEXT NOT NULL
);`
case
"postgres"
:
stmt
=
`CREATE TABLE activity (
id SERIAL PRIMARY KEY,
creator_id INTEGER NOT NULL,
created_ts BIGINT NOT NULL DEFAULT EXTRACT(EPOCH FROM NOW()),
type TEXT NOT NULL DEFAULT '',
level TEXT NOT NULL DEFAULT 'INFO',
payload JSONB NOT NULL DEFAULT '{}'
);`
default
:
return
errors
.
Errorf
(
"unsupported driver: %s"
,
driver
)
}
_
,
err
:=
ts
.
GetDriver
()
.
GetDB
()
.
ExecContext
(
ctx
,
stmt
)
return
err
}
func
insertLegacyInboxActivity
(
ctx
context
.
Context
,
ts
*
store
.
Store
,
driver
string
,
receiverID
,
memoID
,
relatedMemoID
int32
)
error
{
var
insertActivityStmt
string
var
insertInboxStmt
string
payload
:=
fmt
.
Sprintf
(
`{"memoComment":{"memoId":%d,"relatedMemoId":%d}}`
,
memoID
,
relatedMemoID
)
message
:=
`{"type":"MEMO_COMMENT","activityId":1}`
switch
driver
{
case
"sqlite"
,
"mysql"
:
insertActivityStmt
=
`INSERT INTO activity (id, creator_id, type, level, payload) VALUES (?, ?, ?, ?, ?)`
insertInboxStmt
=
`INSERT INTO inbox (sender_id, receiver_id, status, message) VALUES (?, ?, ?, ?)`
case
"postgres"
:
insertActivityStmt
=
`INSERT INTO activity (id, creator_id, type, level, payload) VALUES ($1, $2, $3, $4, $5::jsonb)`
insertInboxStmt
=
`INSERT INTO inbox (sender_id, receiver_id, status, message) VALUES ($1, $2, $3, $4)`
default
:
return
errors
.
Errorf
(
"unsupported driver: %s"
,
driver
)
}
if
_
,
err
:=
ts
.
GetDriver
()
.
GetDB
()
.
ExecContext
(
ctx
,
insertActivityStmt
,
1
,
receiverID
,
"MEMO_COMMENT"
,
"INFO"
,
payload
);
err
!=
nil
{
return
err
}
if
_
,
err
:=
ts
.
GetDriver
()
.
GetDB
()
.
ExecContext
(
ctx
,
insertInboxStmt
,
receiverID
,
receiverID
,
store
.
UNREAD
,
message
);
err
!=
nil
{
return
err
}
return
nil
}
// TestMigrationFromStableVersion verifies that upgrading from a stable Memos version
// TestMigrationFromStableVersion verifies that upgrading from a stable Memos version
// to the current version works correctly. This is the critical upgrade path test.
// to the current version works correctly. This is the critical upgrade path test.
//
//
...
...
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