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
c7970999
Commit
c7970999
authored
Jan 02, 2024
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update resource internal path migrator
parent
0f8bfb63
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
51 additions
and
58 deletions
+51
-58
main.go
bin/memos/main.go
+6
-0
00_resource.sql
store/db/mysql/migration/prod/0.19/00_resource.sql
+0
-19
00_resource.sql
store/db/postgres/migration/prod/0.19/00_resource.sql
+0
-19
00_resource.sql
store/db/sqlite/migration/prod/0.19/00_resource.sql
+0
-19
migrator.go
store/migrator.go
+44
-0
store.go
store/store.go
+1
-1
No files found.
bin/memos/main.go
View file @
c7970999
...
...
@@ -59,6 +59,12 @@ var (
}
store
:=
store
.
New
(
dbDriver
,
profile
)
if
err
:=
store
.
MigrateResourceInternalPath
(
ctx
);
err
!=
nil
{
cancel
()
log
.
Error
(
"failed to migrate resource internal path"
,
zap
.
Error
(
err
))
return
}
s
,
err
:=
server
.
NewServer
(
ctx
,
profile
,
store
)
if
err
!=
nil
{
cancel
()
...
...
store/db/mysql/migration/prod/0.19/00_resource.sql
deleted
100644 → 0
View file @
0f8bfb63
-- Make resource internal_path relative (to MEMOS_DATA) and replace backslash with slash
-- This is a best-effort approach, but even if it fails, it won't break assets from loading
UPDATE
resource
SET
internal_path
=
REPLACE
(
internal_path
,
'
\\
'
,
'/'
)
WHERE
internal_path
LIKE
'%assets
\\\%
'
;
UPDATE
resource
SET
internal_path
=
REPLACE
(
internal_path
,
SUBSTR
(
internal_path
,
1
,
INSTR
(
internal_path
,
'/assets'
)
),
''
);
store/db/postgres/migration/prod/0.19/00_resource.sql
deleted
100644 → 0
View file @
0f8bfb63
-- Make resource internal_path relative (to MEMOS_DATA) and replace backslash with slash
-- This is a best-effort approach, but even if it fails, it won't break assets from loading
UPDATE
resource
SET
internal_path
=
REPLACE
(
internal_path
,
'
\'
, '
/
')
WHERE
internal_path LIKE '
%
assets
\\
%
';
UPDATE resource
SET
internal_path = REPLACE (
internal_path,
SUBSTRING(
internal_path
FROM
1 FOR POSITION('
/
assets
' IN internal_path)
),
''
);
store/db/sqlite/migration/prod/0.19/00_resource.sql
deleted
100644 → 0
View file @
0f8bfb63
-- Make resource internal_path relative (to MEMOS_DATA) and replace backslash with slash
-- This is a best-effort approach, but even if it fails, it won't break assets from loading
UPDATE
resource
SET
internal_path
=
REPLACE
(
internal_path
,
'
\'
, '
/
')
WHERE
internal_path LIKE '
%
assets
\
%
';
UPDATE resource
SET
internal_path = REPLACE (
internal_path,
SUBSTR (
internal_path,
1,
INSTR (internal_path, '
/
assets
')
),
''
);
store/migrator.go
0 → 100644
View file @
c7970999
package
store
import
(
"context"
"path/filepath"
"strings"
"github.com/pkg/errors"
)
// MigrateResourceInternalPath migrates resource internal path from absolute path to relative path.
func
(
s
*
Store
)
MigrateResourceInternalPath
(
ctx
context
.
Context
)
error
{
resources
,
err
:=
s
.
ListResources
(
ctx
,
&
FindResource
{})
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to list resources"
)
}
for
_
,
resource
:=
range
resources
{
if
resource
.
InternalPath
==
""
{
continue
}
internalPath
:=
resource
.
InternalPath
if
filepath
.
IsAbs
(
internalPath
)
{
if
!
strings
.
HasPrefix
(
internalPath
,
s
.
Profile
.
Data
)
{
// Invalid internal path, skip.
continue
}
internalPath
=
strings
.
TrimPrefix
(
internalPath
,
s
.
Profile
.
Data
)
for
strings
.
HasPrefix
(
internalPath
,
"/"
)
{
internalPath
=
strings
.
TrimPrefix
(
internalPath
,
"/"
)
}
_
,
err
:=
s
.
UpdateResource
(
ctx
,
&
UpdateResource
{
ID
:
resource
.
ID
,
InternalPath
:
&
internalPath
,
})
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to update resource"
)
}
}
}
return
nil
}
store/store.go
View file @
c7970999
...
...
@@ -20,8 +20,8 @@ type Store struct {
// New creates a new instance of Store.
func
New
(
driver
Driver
,
profile
*
profile
.
Profile
)
*
Store
{
return
&
Store
{
Profile
:
profile
,
driver
:
driver
,
Profile
:
profile
,
}
}
...
...
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