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
d326c710
Commit
d326c710
authored
Jan 06, 2026
by
Johnny
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor(db): rename tables for clarity - resource→attachment, system_setting→instance_setting
parent
01669685
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
127 additions
and
140 deletions
+127
-140
email_test.go
plugin/email/email_test.go
+7
-19
schema.go
plugin/filter/schema.go
+4
-4
attachment.go
store/db/mysql/attachment.go
+27
-27
instance_setting.go
store/db/mysql/instance_setting.go
+3
-3
attachment.go
store/db/postgres/attachment.go
+28
-28
instance_setting.go
store/db/postgres/instance_setting.go
+3
-3
attachment.go
store/db/sqlite/attachment.go
+28
-28
instance_setting.go
store/db/sqlite/instance_setting.go
+3
-3
00__rename_resource_to_attachment.sql
...igration/mysql/0.26/00__rename_resource_to_attachment.sql
+1
-0
01__rename_system_setting_to_instance_setting.sql
...ql/0.26/01__rename_system_setting_to_instance_setting.sql
+1
-0
LATEST.sql
store/migration/mysql/LATEST.sql
+4
-4
00__rename_resource_to_attachment.sql
...ation/postgres/0.26/00__rename_resource_to_attachment.sql
+1
-0
01__rename_system_setting_to_instance_setting.sql
...es/0.26/01__rename_system_setting_to_instance_setting.sql
+1
-0
LATEST.sql
store/migration/postgres/LATEST.sql
+4
-4
00__rename_resource_to_attachment.sql
...gration/sqlite/0.26/00__rename_resource_to_attachment.sql
+5
-0
01__rename_system_setting_to_instance_setting.sql
...te/0.26/01__rename_system_setting_to_instance_setting.sql
+1
-0
LATEST.sql
store/migration/sqlite/LATEST.sql
+6
-6
00__reset.sql
store/seed/sqlite/00__reset.sql
+0
-11
No files found.
plugin/email/email_test.go
View file @
d326c710
package
email
package
email
import
(
import
(
"sync"
"testing"
"testing"
"time"
"time"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/assert"
"golang.org/x/sync/errgroup"
)
)
func
TestSend
(
t
*
testing
.
T
)
{
func
TestSend
(
t
*
testing
.
T
)
{
...
@@ -106,34 +106,22 @@ func TestSendAsyncConcurrent(t *testing.T) {
...
@@ -106,34 +106,22 @@ func TestSendAsyncConcurrent(t *testing.T) {
FromEmail
:
"test@example.com"
,
FromEmail
:
"test@example.com"
,
}
}
// Send multiple emails concurrently
g
:=
errgroup
.
Group
{}
var
wg
sync
.
WaitGroup
count
:=
5
count
:=
5
for
i
:=
0
;
i
<
count
;
i
++
{
for
i
:=
0
;
i
<
count
;
i
++
{
wg
.
Add
(
1
)
g
.
Go
(
func
()
error
{
go
func
()
{
defer
wg
.
Done
()
message
:=
&
Message
{
message
:=
&
Message
{
To
:
[]
string
{
"recipient@example.com"
},
To
:
[]
string
{
"recipient@example.com"
},
Subject
:
"Concurrent Test"
,
Subject
:
"Concurrent Test"
,
Body
:
"Test body"
,
Body
:
"Test body"
,
}
}
SendAsync
(
config
,
message
)
SendAsync
(
config
,
message
)
}()
return
nil
})
}
}
// Should complete without deadlock
if
err
:=
g
.
Wait
();
err
!=
nil
{
done
:=
make
(
chan
bool
)
t
.
Fatalf
(
"SendAsync calls failed: %v"
,
err
)
go
func
()
{
wg
.
Wait
()
done
<-
true
}()
select
{
case
<-
done
:
// Success
case
<-
time
.
After
(
1
*
time
.
Second
)
:
t
.
Fatal
(
"SendAsync calls did not complete in time"
)
}
}
}
}
plugin/filter/schema.go
View file @
d326c710
...
@@ -256,7 +256,7 @@ func NewAttachmentSchema() Schema {
...
@@ -256,7 +256,7 @@ func NewAttachmentSchema() Schema {
Name
:
"filename"
,
Name
:
"filename"
,
Kind
:
FieldKindScalar
,
Kind
:
FieldKindScalar
,
Type
:
FieldTypeString
,
Type
:
FieldTypeString
,
Column
:
Column
{
Table
:
"
resource
"
,
Name
:
"filename"
},
Column
:
Column
{
Table
:
"
attachment
"
,
Name
:
"filename"
},
SupportsContains
:
true
,
SupportsContains
:
true
,
Expressions
:
map
[
DialectName
]
string
{},
Expressions
:
map
[
DialectName
]
string
{},
},
},
...
@@ -264,14 +264,14 @@ func NewAttachmentSchema() Schema {
...
@@ -264,14 +264,14 @@ func NewAttachmentSchema() Schema {
Name
:
"mime_type"
,
Name
:
"mime_type"
,
Kind
:
FieldKindScalar
,
Kind
:
FieldKindScalar
,
Type
:
FieldTypeString
,
Type
:
FieldTypeString
,
Column
:
Column
{
Table
:
"
resource
"
,
Name
:
"type"
},
Column
:
Column
{
Table
:
"
attachment
"
,
Name
:
"type"
},
Expressions
:
map
[
DialectName
]
string
{},
Expressions
:
map
[
DialectName
]
string
{},
},
},
"create_time"
:
{
"create_time"
:
{
Name
:
"create_time"
,
Name
:
"create_time"
,
Kind
:
FieldKindScalar
,
Kind
:
FieldKindScalar
,
Type
:
FieldTypeTimestamp
,
Type
:
FieldTypeTimestamp
,
Column
:
Column
{
Table
:
"
resource
"
,
Name
:
"created_ts"
},
Column
:
Column
{
Table
:
"
attachment
"
,
Name
:
"created_ts"
},
Expressions
:
map
[
DialectName
]
string
{
Expressions
:
map
[
DialectName
]
string
{
// MySQL stores created_ts as TIMESTAMP, needs conversion to epoch
// MySQL stores created_ts as TIMESTAMP, needs conversion to epoch
DialectMySQL
:
"UNIX_TIMESTAMP(%s)"
,
DialectMySQL
:
"UNIX_TIMESTAMP(%s)"
,
...
@@ -284,7 +284,7 @@ func NewAttachmentSchema() Schema {
...
@@ -284,7 +284,7 @@ func NewAttachmentSchema() Schema {
Name
:
"memo_id"
,
Name
:
"memo_id"
,
Kind
:
FieldKindScalar
,
Kind
:
FieldKindScalar
,
Type
:
FieldTypeInt
,
Type
:
FieldTypeInt
,
Column
:
Column
{
Table
:
"
resource
"
,
Name
:
"memo_id"
},
Column
:
Column
{
Table
:
"
attachment
"
,
Name
:
"memo_id"
},
Expressions
:
map
[
DialectName
]
string
{},
Expressions
:
map
[
DialectName
]
string
{},
AllowedComparisonOps
:
map
[
ComparisonOperator
]
bool
{
AllowedComparisonOps
:
map
[
ComparisonOperator
]
bool
{
CompareEq
:
true
,
CompareEq
:
true
,
...
...
store/db/mysql/attachment.go
View file @
d326c710
...
@@ -31,7 +31,7 @@ func (d *DB) CreateAttachment(ctx context.Context, create *store.Attachment) (*s
...
@@ -31,7 +31,7 @@ func (d *DB) CreateAttachment(ctx context.Context, create *store.Attachment) (*s
}
}
args
:=
[]
any
{
create
.
UID
,
create
.
Filename
,
create
.
Blob
,
create
.
Type
,
create
.
Size
,
create
.
CreatorID
,
create
.
MemoID
,
storageType
,
create
.
Reference
,
payloadString
}
args
:=
[]
any
{
create
.
UID
,
create
.
Filename
,
create
.
Blob
,
create
.
Type
,
create
.
Size
,
create
.
CreatorID
,
create
.
MemoID
,
storageType
,
create
.
Reference
,
payloadString
}
stmt
:=
"INSERT INTO `
resource
` ("
+
strings
.
Join
(
fields
,
", "
)
+
") VALUES ("
+
strings
.
Join
(
placeholder
,
", "
)
+
")"
stmt
:=
"INSERT INTO `
attachment
` ("
+
strings
.
Join
(
fields
,
", "
)
+
") VALUES ("
+
strings
.
Join
(
placeholder
,
", "
)
+
")"
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
args
...
)
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
args
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -50,38 +50,38 @@ func (d *DB) ListAttachments(ctx context.Context, find *store.FindAttachment) ([
...
@@ -50,38 +50,38 @@ func (d *DB) ListAttachments(ctx context.Context, find *store.FindAttachment) ([
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
any
{}
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
any
{}
if
v
:=
find
.
ID
;
v
!=
nil
{
if
v
:=
find
.
ID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource
`.`id` = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"`
attachment
`.`id` = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
UID
;
v
!=
nil
{
if
v
:=
find
.
UID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource
`.`uid` = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"`
attachment
`.`uid` = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
CreatorID
;
v
!=
nil
{
if
v
:=
find
.
CreatorID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource
`.`creator_id` = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"`
attachment
`.`creator_id` = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
Filename
;
v
!=
nil
{
if
v
:=
find
.
Filename
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource
`.`filename` = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"`
attachment
`.`filename` = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
FilenameSearch
;
v
!=
nil
{
if
v
:=
find
.
FilenameSearch
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource
`.`filename` LIKE ?"
),
append
(
args
,
"%"
+*
v
+
"%"
)
where
,
args
=
append
(
where
,
"`
attachment
`.`filename` LIKE ?"
),
append
(
args
,
"%"
+*
v
+
"%"
)
}
}
if
v
:=
find
.
MemoID
;
v
!=
nil
{
if
v
:=
find
.
MemoID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource
`.`memo_id` = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"`
attachment
`.`memo_id` = ?"
),
append
(
args
,
*
v
)
}
}
if
len
(
find
.
MemoIDList
)
>
0
{
if
len
(
find
.
MemoIDList
)
>
0
{
placeholders
:=
make
([]
string
,
0
,
len
(
find
.
MemoIDList
))
placeholders
:=
make
([]
string
,
0
,
len
(
find
.
MemoIDList
))
for
range
find
.
MemoIDList
{
for
range
find
.
MemoIDList
{
placeholders
=
append
(
placeholders
,
"?"
)
placeholders
=
append
(
placeholders
,
"?"
)
}
}
where
=
append
(
where
,
"`
resource
`.`memo_id` IN ("
+
strings
.
Join
(
placeholders
,
","
)
+
")"
)
where
=
append
(
where
,
"`
attachment
`.`memo_id` IN ("
+
strings
.
Join
(
placeholders
,
","
)
+
")"
)
for
_
,
id
:=
range
find
.
MemoIDList
{
for
_
,
id
:=
range
find
.
MemoIDList
{
args
=
append
(
args
,
id
)
args
=
append
(
args
,
id
)
}
}
}
}
if
find
.
HasRelatedMemo
{
if
find
.
HasRelatedMemo
{
where
=
append
(
where
,
"`
resource
`.`memo_id` IS NOT NULL"
)
where
=
append
(
where
,
"`
attachment
`.`memo_id` IS NOT NULL"
)
}
}
if
find
.
StorageType
!=
nil
{
if
find
.
StorageType
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource
`.`storage_type` = ?"
),
append
(
args
,
find
.
StorageType
.
String
())
where
,
args
=
append
(
where
,
"`
attachment
`.`storage_type` = ?"
),
append
(
args
,
find
.
StorageType
.
String
())
}
}
if
len
(
find
.
Filters
)
>
0
{
if
len
(
find
.
Filters
)
>
0
{
...
@@ -95,26 +95,26 @@ func (d *DB) ListAttachments(ctx context.Context, find *store.FindAttachment) ([
...
@@ -95,26 +95,26 @@ func (d *DB) ListAttachments(ctx context.Context, find *store.FindAttachment) ([
}
}
fields
:=
[]
string
{
fields
:=
[]
string
{
"`
resource
`.`id` AS `id`"
,
"`
attachment
`.`id` AS `id`"
,
"`
resource
`.`uid` AS `uid`"
,
"`
attachment
`.`uid` AS `uid`"
,
"`
resource
`.`filename` AS `filename`"
,
"`
attachment
`.`filename` AS `filename`"
,
"`
resource
`.`type` AS `type`"
,
"`
attachment
`.`type` AS `type`"
,
"`
resource
`.`size` AS `size`"
,
"`
attachment
`.`size` AS `size`"
,
"`
resource
`.`creator_id` AS `creator_id`"
,
"`
attachment
`.`creator_id` AS `creator_id`"
,
"UNIX_TIMESTAMP(`
resource
`.`created_ts`) AS `created_ts`"
,
"UNIX_TIMESTAMP(`
attachment
`.`created_ts`) AS `created_ts`"
,
"UNIX_TIMESTAMP(`
resource
`.`updated_ts`) AS `updated_ts`"
,
"UNIX_TIMESTAMP(`
attachment
`.`updated_ts`) AS `updated_ts`"
,
"`
resource
`.`memo_id` AS `memo_id`"
,
"`
attachment
`.`memo_id` AS `memo_id`"
,
"`
resource
`.`storage_type` AS `storage_type`"
,
"`
attachment
`.`storage_type` AS `storage_type`"
,
"`
resource
`.`reference` AS `reference`"
,
"`
attachment
`.`reference` AS `reference`"
,
"`
resource
`.`payload` AS `payload`"
,
"`
attachment
`.`payload` AS `payload`"
,
"CASE WHEN `memo`.`uid` IS NOT NULL THEN `memo`.`uid` ELSE NULL END AS `memo_uid`"
,
"CASE WHEN `memo`.`uid` IS NOT NULL THEN `memo`.`uid` ELSE NULL END AS `memo_uid`"
,
}
}
if
find
.
GetBlob
{
if
find
.
GetBlob
{
fields
=
append
(
fields
,
"`
resource
`.`blob` AS `blob`"
)
fields
=
append
(
fields
,
"`
attachment
`.`blob` AS `blob`"
)
}
}
query
:=
"SELECT "
+
strings
.
Join
(
fields
,
", "
)
+
" FROM `
resource
`"
+
" "
+
query
:=
"SELECT "
+
strings
.
Join
(
fields
,
", "
)
+
" FROM `
attachment
`"
+
" "
+
"LEFT JOIN `memo` ON `
resource
`.`memo_id` = `memo`.`id`"
+
" "
+
"LEFT JOIN `memo` ON `
attachment
`.`memo_id` = `memo`.`id`"
+
" "
+
"WHERE "
+
strings
.
Join
(
where
,
" AND "
)
+
" "
+
"WHERE "
+
strings
.
Join
(
where
,
" AND "
)
+
" "
+
"ORDER BY `updated_ts` DESC"
"ORDER BY `updated_ts` DESC"
if
find
.
Limit
!=
nil
{
if
find
.
Limit
!=
nil
{
...
@@ -216,7 +216,7 @@ func (d *DB) UpdateAttachment(ctx context.Context, update *store.UpdateAttachmen
...
@@ -216,7 +216,7 @@ func (d *DB) UpdateAttachment(ctx context.Context, update *store.UpdateAttachmen
}
}
args
=
append
(
args
,
update
.
ID
)
args
=
append
(
args
,
update
.
ID
)
stmt
:=
"UPDATE `
resource
` SET "
+
strings
.
Join
(
set
,
", "
)
+
" WHERE `id` = ?"
stmt
:=
"UPDATE `
attachment
` SET "
+
strings
.
Join
(
set
,
", "
)
+
" WHERE `id` = ?"
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
args
...
)
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
args
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
@@ -228,7 +228,7 @@ func (d *DB) UpdateAttachment(ctx context.Context, update *store.UpdateAttachmen
...
@@ -228,7 +228,7 @@ func (d *DB) UpdateAttachment(ctx context.Context, update *store.UpdateAttachmen
}
}
func
(
d
*
DB
)
DeleteAttachment
(
ctx
context
.
Context
,
delete
*
store
.
DeleteAttachment
)
error
{
func
(
d
*
DB
)
DeleteAttachment
(
ctx
context
.
Context
,
delete
*
store
.
DeleteAttachment
)
error
{
stmt
:=
"DELETE FROM `
resource
` WHERE `id` = ?"
stmt
:=
"DELETE FROM `
attachment
` WHERE `id` = ?"
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
delete
.
ID
)
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
delete
.
ID
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
store/db/mysql/instance_setting.go
View file @
d326c710
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
)
)
func
(
d
*
DB
)
UpsertInstanceSetting
(
ctx
context
.
Context
,
upsert
*
store
.
InstanceSetting
)
(
*
store
.
InstanceSetting
,
error
)
{
func
(
d
*
DB
)
UpsertInstanceSetting
(
ctx
context
.
Context
,
upsert
*
store
.
InstanceSetting
)
(
*
store
.
InstanceSetting
,
error
)
{
stmt
:=
"INSERT INTO `
system
_setting` (`name`, `value`, `description`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE `value` = ?, `description` = ?"
stmt
:=
"INSERT INTO `
instance
_setting` (`name`, `value`, `description`) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE `value` = ?, `description` = ?"
_
,
err
:=
d
.
db
.
ExecContext
(
_
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
ctx
,
stmt
,
stmt
,
...
@@ -31,7 +31,7 @@ func (d *DB) ListInstanceSettings(ctx context.Context, find *store.FindInstanceS
...
@@ -31,7 +31,7 @@ func (d *DB) ListInstanceSettings(ctx context.Context, find *store.FindInstanceS
where
,
args
=
append
(
where
,
"`name` = ?"
),
append
(
args
,
find
.
Name
)
where
,
args
=
append
(
where
,
"`name` = ?"
),
append
(
args
,
find
.
Name
)
}
}
query
:=
"SELECT `name`, `value`, `description` FROM `
system
_setting` WHERE "
+
strings
.
Join
(
where
,
" AND "
)
query
:=
"SELECT `name`, `value`, `description` FROM `
instance
_setting` WHERE "
+
strings
.
Join
(
where
,
" AND "
)
rows
,
err
:=
d
.
db
.
QueryContext
(
ctx
,
query
,
args
...
)
rows
,
err
:=
d
.
db
.
QueryContext
(
ctx
,
query
,
args
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -59,7 +59,7 @@ func (d *DB) ListInstanceSettings(ctx context.Context, find *store.FindInstanceS
...
@@ -59,7 +59,7 @@ func (d *DB) ListInstanceSettings(ctx context.Context, find *store.FindInstanceS
}
}
func
(
d
*
DB
)
DeleteInstanceSetting
(
ctx
context
.
Context
,
delete
*
store
.
DeleteInstanceSetting
)
error
{
func
(
d
*
DB
)
DeleteInstanceSetting
(
ctx
context
.
Context
,
delete
*
store
.
DeleteInstanceSetting
)
error
{
stmt
:=
"DELETE FROM `
system
_setting` WHERE `name` = ?"
stmt
:=
"DELETE FROM `
instance
_setting` WHERE `name` = ?"
_
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
delete
.
Name
)
_
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
delete
.
Name
)
return
err
return
err
}
}
store/db/postgres/attachment.go
View file @
d326c710
...
@@ -30,7 +30,7 @@ func (d *DB) CreateAttachment(ctx context.Context, create *store.Attachment) (*s
...
@@ -30,7 +30,7 @@ func (d *DB) CreateAttachment(ctx context.Context, create *store.Attachment) (*s
}
}
args
:=
[]
any
{
create
.
UID
,
create
.
Filename
,
create
.
Blob
,
create
.
Type
,
create
.
Size
,
create
.
CreatorID
,
create
.
MemoID
,
storageType
,
create
.
Reference
,
payloadString
}
args
:=
[]
any
{
create
.
UID
,
create
.
Filename
,
create
.
Blob
,
create
.
Type
,
create
.
Size
,
create
.
CreatorID
,
create
.
MemoID
,
storageType
,
create
.
Reference
,
payloadString
}
stmt
:=
"INSERT INTO
resource
("
+
strings
.
Join
(
fields
,
", "
)
+
") VALUES ("
+
placeholders
(
len
(
args
))
+
") RETURNING id, created_ts, updated_ts"
stmt
:=
"INSERT INTO
attachment
("
+
strings
.
Join
(
fields
,
", "
)
+
") VALUES ("
+
placeholders
(
len
(
args
))
+
") RETURNING id, created_ts, updated_ts"
if
err
:=
d
.
db
.
QueryRowContext
(
ctx
,
stmt
,
args
...
)
.
Scan
(
&
create
.
ID
,
&
create
.
CreatedTs
,
&
create
.
UpdatedTs
);
err
!=
nil
{
if
err
:=
d
.
db
.
QueryRowContext
(
ctx
,
stmt
,
args
...
)
.
Scan
(
&
create
.
ID
,
&
create
.
CreatedTs
,
&
create
.
UpdatedTs
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -41,22 +41,22 @@ func (d *DB) ListAttachments(ctx context.Context, find *store.FindAttachment) ([
...
@@ -41,22 +41,22 @@ func (d *DB) ListAttachments(ctx context.Context, find *store.FindAttachment) ([
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
any
{}
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
any
{}
if
v
:=
find
.
ID
;
v
!=
nil
{
if
v
:=
find
.
ID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"
resource
.id = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"
attachment
.id = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
UID
;
v
!=
nil
{
if
v
:=
find
.
UID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"
resource
.uid = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"
attachment
.uid = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
CreatorID
;
v
!=
nil
{
if
v
:=
find
.
CreatorID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"
resource
.creator_id = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"
attachment
.creator_id = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
Filename
;
v
!=
nil
{
if
v
:=
find
.
Filename
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"
resource
.filename = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"
attachment
.filename = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
FilenameSearch
;
v
!=
nil
{
if
v
:=
find
.
FilenameSearch
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"
resource
.filename LIKE "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
fmt
.
Sprintf
(
"%%%s%%"
,
*
v
))
where
,
args
=
append
(
where
,
"
attachment
.filename LIKE "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
fmt
.
Sprintf
(
"%%%s%%"
,
*
v
))
}
}
if
v
:=
find
.
MemoID
;
v
!=
nil
{
if
v
:=
find
.
MemoID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"
resource
.memo_id = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"
attachment
.memo_id = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
*
v
)
}
}
if
len
(
find
.
MemoIDList
)
>
0
{
if
len
(
find
.
MemoIDList
)
>
0
{
holders
:=
make
([]
string
,
0
,
len
(
find
.
MemoIDList
))
holders
:=
make
([]
string
,
0
,
len
(
find
.
MemoIDList
))
...
@@ -64,13 +64,13 @@ func (d *DB) ListAttachments(ctx context.Context, find *store.FindAttachment) ([
...
@@ -64,13 +64,13 @@ func (d *DB) ListAttachments(ctx context.Context, find *store.FindAttachment) ([
holders
=
append
(
holders
,
placeholder
(
len
(
args
)
+
1
))
holders
=
append
(
holders
,
placeholder
(
len
(
args
)
+
1
))
args
=
append
(
args
,
id
)
args
=
append
(
args
,
id
)
}
}
where
=
append
(
where
,
"
resource
.memo_id IN ("
+
strings
.
Join
(
holders
,
", "
)
+
")"
)
where
=
append
(
where
,
"
attachment
.memo_id IN ("
+
strings
.
Join
(
holders
,
", "
)
+
")"
)
}
}
if
find
.
HasRelatedMemo
{
if
find
.
HasRelatedMemo
{
where
=
append
(
where
,
"
resource
.memo_id IS NOT NULL"
)
where
=
append
(
where
,
"
attachment
.memo_id IS NOT NULL"
)
}
}
if
v
:=
find
.
StorageType
;
v
!=
nil
{
if
v
:=
find
.
StorageType
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"
resource
.storage_type = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
v
.
String
())
where
,
args
=
append
(
where
,
"
attachment
.storage_type = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
v
.
String
())
}
}
if
len
(
find
.
Filters
)
>
0
{
if
len
(
find
.
Filters
)
>
0
{
...
@@ -84,31 +84,31 @@ func (d *DB) ListAttachments(ctx context.Context, find *store.FindAttachment) ([
...
@@ -84,31 +84,31 @@ func (d *DB) ListAttachments(ctx context.Context, find *store.FindAttachment) ([
}
}
fields
:=
[]
string
{
fields
:=
[]
string
{
"
resource
.id AS id"
,
"
attachment
.id AS id"
,
"
resource
.uid AS uid"
,
"
attachment
.uid AS uid"
,
"
resource
.filename AS filename"
,
"
attachment
.filename AS filename"
,
"
resource
.type AS type"
,
"
attachment
.type AS type"
,
"
resource
.size AS size"
,
"
attachment
.size AS size"
,
"
resource
.creator_id AS creator_id"
,
"
attachment
.creator_id AS creator_id"
,
"
resource
.created_ts AS created_ts"
,
"
attachment
.created_ts AS created_ts"
,
"
resource
.updated_ts AS updated_ts"
,
"
attachment
.updated_ts AS updated_ts"
,
"
resource
.memo_id AS memo_id"
,
"
attachment
.memo_id AS memo_id"
,
"
resource
.storage_type AS storage_type"
,
"
attachment
.storage_type AS storage_type"
,
"
resource
.reference AS reference"
,
"
attachment
.reference AS reference"
,
"
resource
.payload AS payload"
,
"
attachment
.payload AS payload"
,
"CASE WHEN memo.uid IS NOT NULL THEN memo.uid ELSE NULL END AS memo_uid"
,
"CASE WHEN memo.uid IS NOT NULL THEN memo.uid ELSE NULL END AS memo_uid"
,
}
}
if
find
.
GetBlob
{
if
find
.
GetBlob
{
fields
=
append
(
fields
,
"
resource
.blob AS blob"
)
fields
=
append
(
fields
,
"
attachment
.blob AS blob"
)
}
}
query
:=
fmt
.
Sprintf
(
`
query
:=
fmt
.
Sprintf
(
`
SELECT
SELECT
%s
%s
FROM
resource
FROM
attachment
LEFT JOIN memo ON
resource
.memo_id = memo.id
LEFT JOIN memo ON
attachment
.memo_id = memo.id
WHERE %s
WHERE %s
ORDER BY
resource
.updated_ts DESC
ORDER BY
attachment
.updated_ts DESC
`
,
strings
.
Join
(
fields
,
", "
),
strings
.
Join
(
where
,
" AND "
))
`
,
strings
.
Join
(
fields
,
", "
),
strings
.
Join
(
where
,
" AND "
))
if
find
.
Limit
!=
nil
{
if
find
.
Limit
!=
nil
{
query
=
fmt
.
Sprintf
(
"%s LIMIT %d"
,
query
,
*
find
.
Limit
)
query
=
fmt
.
Sprintf
(
"%s LIMIT %d"
,
query
,
*
find
.
Limit
)
...
@@ -196,7 +196,7 @@ func (d *DB) UpdateAttachment(ctx context.Context, update *store.UpdateAttachmen
...
@@ -196,7 +196,7 @@ func (d *DB) UpdateAttachment(ctx context.Context, update *store.UpdateAttachmen
set
,
args
=
append
(
set
,
"payload = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
string
(
bytes
))
set
,
args
=
append
(
set
,
"payload = "
+
placeholder
(
len
(
args
)
+
1
)),
append
(
args
,
string
(
bytes
))
}
}
stmt
:=
`UPDATE
resource
SET `
+
strings
.
Join
(
set
,
", "
)
+
` WHERE id = `
+
placeholder
(
len
(
args
)
+
1
)
stmt
:=
`UPDATE
attachment
SET `
+
strings
.
Join
(
set
,
", "
)
+
` WHERE id = `
+
placeholder
(
len
(
args
)
+
1
)
args
=
append
(
args
,
update
.
ID
)
args
=
append
(
args
,
update
.
ID
)
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
args
...
)
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
args
...
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -209,7 +209,7 @@ func (d *DB) UpdateAttachment(ctx context.Context, update *store.UpdateAttachmen
...
@@ -209,7 +209,7 @@ func (d *DB) UpdateAttachment(ctx context.Context, update *store.UpdateAttachmen
}
}
func
(
d
*
DB
)
DeleteAttachment
(
ctx
context
.
Context
,
delete
*
store
.
DeleteAttachment
)
error
{
func
(
d
*
DB
)
DeleteAttachment
(
ctx
context
.
Context
,
delete
*
store
.
DeleteAttachment
)
error
{
stmt
:=
`DELETE FROM
resource
WHERE id = $1`
stmt
:=
`DELETE FROM
attachment
WHERE id = $1`
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
delete
.
ID
)
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
delete
.
ID
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
store/db/postgres/instance_setting.go
View file @
d326c710
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
func
(
d
*
DB
)
UpsertInstanceSetting
(
ctx
context
.
Context
,
upsert
*
store
.
InstanceSetting
)
(
*
store
.
InstanceSetting
,
error
)
{
func
(
d
*
DB
)
UpsertInstanceSetting
(
ctx
context
.
Context
,
upsert
*
store
.
InstanceSetting
)
(
*
store
.
InstanceSetting
,
error
)
{
stmt
:=
`
stmt
:=
`
INSERT INTO
system
_setting (
INSERT INTO
instance
_setting (
name, value, description
name, value, description
)
)
VALUES ($1, $2, $3)
VALUES ($1, $2, $3)
...
@@ -36,7 +36,7 @@ func (d *DB) ListInstanceSettings(ctx context.Context, find *store.FindInstanceS
...
@@ -36,7 +36,7 @@ func (d *DB) ListInstanceSettings(ctx context.Context, find *store.FindInstanceS
name,
name,
value,
value,
description
description
FROM
system
_setting
FROM
instance
_setting
WHERE `
+
strings
.
Join
(
where
,
" AND "
)
WHERE `
+
strings
.
Join
(
where
,
" AND "
)
rows
,
err
:=
d
.
db
.
QueryContext
(
ctx
,
query
,
args
...
)
rows
,
err
:=
d
.
db
.
QueryContext
(
ctx
,
query
,
args
...
)
...
@@ -66,7 +66,7 @@ func (d *DB) ListInstanceSettings(ctx context.Context, find *store.FindInstanceS
...
@@ -66,7 +66,7 @@ func (d *DB) ListInstanceSettings(ctx context.Context, find *store.FindInstanceS
}
}
func
(
d
*
DB
)
DeleteInstanceSetting
(
ctx
context
.
Context
,
delete
*
store
.
DeleteInstanceSetting
)
error
{
func
(
d
*
DB
)
DeleteInstanceSetting
(
ctx
context
.
Context
,
delete
*
store
.
DeleteInstanceSetting
)
error
{
stmt
:=
`DELETE FROM
system
_setting WHERE name = $1`
stmt
:=
`DELETE FROM
instance
_setting WHERE name = $1`
_
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
delete
.
Name
)
_
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
delete
.
Name
)
return
err
return
err
}
}
store/db/sqlite/attachment.go
View file @
d326c710
...
@@ -31,7 +31,7 @@ func (d *DB) CreateAttachment(ctx context.Context, create *store.Attachment) (*s
...
@@ -31,7 +31,7 @@ func (d *DB) CreateAttachment(ctx context.Context, create *store.Attachment) (*s
}
}
args
:=
[]
any
{
create
.
UID
,
create
.
Filename
,
create
.
Blob
,
create
.
Type
,
create
.
Size
,
create
.
CreatorID
,
create
.
MemoID
,
storageType
,
create
.
Reference
,
payloadString
}
args
:=
[]
any
{
create
.
UID
,
create
.
Filename
,
create
.
Blob
,
create
.
Type
,
create
.
Size
,
create
.
CreatorID
,
create
.
MemoID
,
storageType
,
create
.
Reference
,
payloadString
}
stmt
:=
"INSERT INTO `
resource
` ("
+
strings
.
Join
(
fields
,
", "
)
+
") VALUES ("
+
strings
.
Join
(
placeholder
,
", "
)
+
") RETURNING `id`, `created_ts`, `updated_ts`"
stmt
:=
"INSERT INTO `
attachment
` ("
+
strings
.
Join
(
fields
,
", "
)
+
") VALUES ("
+
strings
.
Join
(
placeholder
,
", "
)
+
") RETURNING `id`, `created_ts`, `updated_ts`"
if
err
:=
d
.
db
.
QueryRowContext
(
ctx
,
stmt
,
args
...
)
.
Scan
(
&
create
.
ID
,
&
create
.
CreatedTs
,
&
create
.
UpdatedTs
);
err
!=
nil
{
if
err
:=
d
.
db
.
QueryRowContext
(
ctx
,
stmt
,
args
...
)
.
Scan
(
&
create
.
ID
,
&
create
.
CreatedTs
,
&
create
.
UpdatedTs
);
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -43,38 +43,38 @@ func (d *DB) ListAttachments(ctx context.Context, find *store.FindAttachment) ([
...
@@ -43,38 +43,38 @@ func (d *DB) ListAttachments(ctx context.Context, find *store.FindAttachment) ([
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
any
{}
where
,
args
:=
[]
string
{
"1 = 1"
},
[]
any
{}
if
v
:=
find
.
ID
;
v
!=
nil
{
if
v
:=
find
.
ID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource
`.`id` = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"`
attachment
`.`id` = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
UID
;
v
!=
nil
{
if
v
:=
find
.
UID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource
`.`uid` = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"`
attachment
`.`uid` = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
CreatorID
;
v
!=
nil
{
if
v
:=
find
.
CreatorID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource
`.`creator_id` = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"`
attachment
`.`creator_id` = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
Filename
;
v
!=
nil
{
if
v
:=
find
.
Filename
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource
`.`filename` = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"`
attachment
`.`filename` = ?"
),
append
(
args
,
*
v
)
}
}
if
v
:=
find
.
FilenameSearch
;
v
!=
nil
{
if
v
:=
find
.
FilenameSearch
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource
`.`filename` LIKE ?"
),
append
(
args
,
fmt
.
Sprintf
(
"%%%s%%"
,
*
v
))
where
,
args
=
append
(
where
,
"`
attachment
`.`filename` LIKE ?"
),
append
(
args
,
fmt
.
Sprintf
(
"%%%s%%"
,
*
v
))
}
}
if
v
:=
find
.
MemoID
;
v
!=
nil
{
if
v
:=
find
.
MemoID
;
v
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource
`.`memo_id` = ?"
),
append
(
args
,
*
v
)
where
,
args
=
append
(
where
,
"`
attachment
`.`memo_id` = ?"
),
append
(
args
,
*
v
)
}
}
if
len
(
find
.
MemoIDList
)
>
0
{
if
len
(
find
.
MemoIDList
)
>
0
{
placeholders
:=
make
([]
string
,
0
,
len
(
find
.
MemoIDList
))
placeholders
:=
make
([]
string
,
0
,
len
(
find
.
MemoIDList
))
for
range
find
.
MemoIDList
{
for
range
find
.
MemoIDList
{
placeholders
=
append
(
placeholders
,
"?"
)
placeholders
=
append
(
placeholders
,
"?"
)
}
}
where
=
append
(
where
,
"`
resource
`.`memo_id` IN ("
+
strings
.
Join
(
placeholders
,
","
)
+
")"
)
where
=
append
(
where
,
"`
attachment
`.`memo_id` IN ("
+
strings
.
Join
(
placeholders
,
","
)
+
")"
)
for
_
,
id
:=
range
find
.
MemoIDList
{
for
_
,
id
:=
range
find
.
MemoIDList
{
args
=
append
(
args
,
id
)
args
=
append
(
args
,
id
)
}
}
}
}
if
find
.
HasRelatedMemo
{
if
find
.
HasRelatedMemo
{
where
=
append
(
where
,
"`
resource
`.`memo_id` IS NOT NULL"
)
where
=
append
(
where
,
"`
attachment
`.`memo_id` IS NOT NULL"
)
}
}
if
find
.
StorageType
!=
nil
{
if
find
.
StorageType
!=
nil
{
where
,
args
=
append
(
where
,
"`
resource
`.`storage_type` = ?"
),
append
(
args
,
find
.
StorageType
.
String
())
where
,
args
=
append
(
where
,
"`
attachment
`.`storage_type` = ?"
),
append
(
args
,
find
.
StorageType
.
String
())
}
}
if
len
(
find
.
Filters
)
>
0
{
if
len
(
find
.
Filters
)
>
0
{
...
@@ -88,28 +88,28 @@ func (d *DB) ListAttachments(ctx context.Context, find *store.FindAttachment) ([
...
@@ -88,28 +88,28 @@ func (d *DB) ListAttachments(ctx context.Context, find *store.FindAttachment) ([
}
}
fields
:=
[]
string
{
fields
:=
[]
string
{
"`
resource
`.`id` AS `id`"
,
"`
attachment
`.`id` AS `id`"
,
"`
resource
`.`uid` AS `uid`"
,
"`
attachment
`.`uid` AS `uid`"
,
"`
resource
`.`filename` AS `filename`"
,
"`
attachment
`.`filename` AS `filename`"
,
"`
resource
`.`type` AS `type`"
,
"`
attachment
`.`type` AS `type`"
,
"`
resource
`.`size` AS `size`"
,
"`
attachment
`.`size` AS `size`"
,
"`
resource
`.`creator_id` AS `creator_id`"
,
"`
attachment
`.`creator_id` AS `creator_id`"
,
"`
resource
`.`created_ts` AS `created_ts`"
,
"`
attachment
`.`created_ts` AS `created_ts`"
,
"`
resource
`.`updated_ts` AS `updated_ts`"
,
"`
attachment
`.`updated_ts` AS `updated_ts`"
,
"`
resource
`.`memo_id` AS `memo_id`"
,
"`
attachment
`.`memo_id` AS `memo_id`"
,
"`
resource
`.`storage_type` AS `storage_type`"
,
"`
attachment
`.`storage_type` AS `storage_type`"
,
"`
resource
`.`reference` AS `reference`"
,
"`
attachment
`.`reference` AS `reference`"
,
"`
resource
`.`payload` AS `payload`"
,
"`
attachment
`.`payload` AS `payload`"
,
"CASE WHEN `memo`.`uid` IS NOT NULL THEN `memo`.`uid` ELSE NULL END AS `memo_uid`"
,
"CASE WHEN `memo`.`uid` IS NOT NULL THEN `memo`.`uid` ELSE NULL END AS `memo_uid`"
,
}
}
if
find
.
GetBlob
{
if
find
.
GetBlob
{
fields
=
append
(
fields
,
"`
resource
`.`blob` AS `blob`"
)
fields
=
append
(
fields
,
"`
attachment
`.`blob` AS `blob`"
)
}
}
query
:=
"SELECT "
+
strings
.
Join
(
fields
,
", "
)
+
" FROM `
resource
`"
+
" "
+
query
:=
"SELECT "
+
strings
.
Join
(
fields
,
", "
)
+
" FROM `
attachment
`"
+
" "
+
"LEFT JOIN `memo` ON `
resource
`.`memo_id` = `memo`.`id`"
+
" "
+
"LEFT JOIN `memo` ON `
attachment
`.`memo_id` = `memo`.`id`"
+
" "
+
"WHERE "
+
strings
.
Join
(
where
,
" AND "
)
+
" "
+
"WHERE "
+
strings
.
Join
(
where
,
" AND "
)
+
" "
+
"ORDER BY `
resource
`.`updated_ts` DESC"
"ORDER BY `
attachment
`.`updated_ts` DESC"
if
find
.
Limit
!=
nil
{
if
find
.
Limit
!=
nil
{
query
=
fmt
.
Sprintf
(
"%s LIMIT %d"
,
query
,
*
find
.
Limit
)
query
=
fmt
.
Sprintf
(
"%s LIMIT %d"
,
query
,
*
find
.
Limit
)
if
find
.
Offset
!=
nil
{
if
find
.
Offset
!=
nil
{
...
@@ -197,7 +197,7 @@ func (d *DB) UpdateAttachment(ctx context.Context, update *store.UpdateAttachmen
...
@@ -197,7 +197,7 @@ func (d *DB) UpdateAttachment(ctx context.Context, update *store.UpdateAttachmen
}
}
args
=
append
(
args
,
update
.
ID
)
args
=
append
(
args
,
update
.
ID
)
stmt
:=
"UPDATE `
resource
` SET "
+
strings
.
Join
(
set
,
", "
)
+
" WHERE `id` = ?"
stmt
:=
"UPDATE `
attachment
` SET "
+
strings
.
Join
(
set
,
", "
)
+
" WHERE `id` = ?"
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
args
...
)
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
args
...
)
if
err
!=
nil
{
if
err
!=
nil
{
return
errors
.
Wrap
(
err
,
"failed to update attachment"
)
return
errors
.
Wrap
(
err
,
"failed to update attachment"
)
...
@@ -209,7 +209,7 @@ func (d *DB) UpdateAttachment(ctx context.Context, update *store.UpdateAttachmen
...
@@ -209,7 +209,7 @@ func (d *DB) UpdateAttachment(ctx context.Context, update *store.UpdateAttachmen
}
}
func
(
d
*
DB
)
DeleteAttachment
(
ctx
context
.
Context
,
delete
*
store
.
DeleteAttachment
)
error
{
func
(
d
*
DB
)
DeleteAttachment
(
ctx
context
.
Context
,
delete
*
store
.
DeleteAttachment
)
error
{
stmt
:=
"DELETE FROM `
resource
` WHERE `id` = ?"
stmt
:=
"DELETE FROM `
attachment
` WHERE `id` = ?"
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
delete
.
ID
)
result
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
delete
.
ID
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
...
...
store/db/sqlite/instance_setting.go
View file @
d326c710
...
@@ -9,7 +9,7 @@ import (
...
@@ -9,7 +9,7 @@ import (
func
(
d
*
DB
)
UpsertInstanceSetting
(
ctx
context
.
Context
,
upsert
*
store
.
InstanceSetting
)
(
*
store
.
InstanceSetting
,
error
)
{
func
(
d
*
DB
)
UpsertInstanceSetting
(
ctx
context
.
Context
,
upsert
*
store
.
InstanceSetting
)
(
*
store
.
InstanceSetting
,
error
)
{
stmt
:=
`
stmt
:=
`
INSERT INTO
system
_setting (
INSERT INTO
instance
_setting (
name, value, description
name, value, description
)
)
VALUES (?, ?, ?)
VALUES (?, ?, ?)
...
@@ -36,7 +36,7 @@ func (d *DB) ListInstanceSettings(ctx context.Context, find *store.FindInstanceS
...
@@ -36,7 +36,7 @@ func (d *DB) ListInstanceSettings(ctx context.Context, find *store.FindInstanceS
name,
name,
value,
value,
description
description
FROM
system
_setting
FROM
instance
_setting
WHERE `
+
strings
.
Join
(
where
,
" AND "
)
WHERE `
+
strings
.
Join
(
where
,
" AND "
)
rows
,
err
:=
d
.
db
.
QueryContext
(
ctx
,
query
,
args
...
)
rows
,
err
:=
d
.
db
.
QueryContext
(
ctx
,
query
,
args
...
)
...
@@ -66,7 +66,7 @@ func (d *DB) ListInstanceSettings(ctx context.Context, find *store.FindInstanceS
...
@@ -66,7 +66,7 @@ func (d *DB) ListInstanceSettings(ctx context.Context, find *store.FindInstanceS
}
}
func
(
d
*
DB
)
DeleteInstanceSetting
(
ctx
context
.
Context
,
delete
*
store
.
DeleteInstanceSetting
)
error
{
func
(
d
*
DB
)
DeleteInstanceSetting
(
ctx
context
.
Context
,
delete
*
store
.
DeleteInstanceSetting
)
error
{
stmt
:=
"DELETE FROM
system
_setting WHERE name = ?"
stmt
:=
"DELETE FROM
instance
_setting WHERE name = ?"
_
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
delete
.
Name
)
_
,
err
:=
d
.
db
.
ExecContext
(
ctx
,
stmt
,
delete
.
Name
)
return
err
return
err
}
}
store/migration/mysql/0.26/00__rename_resource_to_attachment.sql
0 → 100644
View file @
d326c710
RENAME
TABLE
resource
TO
attachment
;
store/migration/mysql/0.26/01__rename_system_setting_to_instance_setting.sql
0 → 100644
View file @
d326c710
RENAME
TABLE
system_setting
TO
instance_setting
;
store/migration/mysql/LATEST.sql
View file @
d326c710
--
system
_setting
--
instance
_setting
CREATE
TABLE
`
system
_setting`
(
CREATE
TABLE
`
instance
_setting`
(
`name`
VARCHAR
(
256
)
NOT
NULL
PRIMARY
KEY
,
`name`
VARCHAR
(
256
)
NOT
NULL
PRIMARY
KEY
,
`value`
LONGTEXT
NOT
NULL
,
`value`
LONGTEXT
NOT
NULL
,
`description`
TEXT
NOT
NULL
`description`
TEXT
NOT
NULL
...
@@ -58,8 +58,8 @@ CREATE TABLE `memo_relation` (
...
@@ -58,8 +58,8 @@ CREATE TABLE `memo_relation` (
UNIQUE
(
`memo_id`
,
`related_memo_id`
,
`type`
)
UNIQUE
(
`memo_id`
,
`related_memo_id`
,
`type`
)
);
);
--
resource
--
attachment
CREATE
TABLE
`
resource
`
(
CREATE
TABLE
`
attachment
`
(
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`id`
INT
NOT
NULL
AUTO_INCREMENT
PRIMARY
KEY
,
`uid`
VARCHAR
(
256
)
NOT
NULL
UNIQUE
,
`uid`
VARCHAR
(
256
)
NOT
NULL
UNIQUE
,
`creator_id`
INT
NOT
NULL
,
`creator_id`
INT
NOT
NULL
,
...
...
store/migration/postgres/0.26/00__rename_resource_to_attachment.sql
0 → 100644
View file @
d326c710
ALTER
TABLE
resource
RENAME
TO
attachment
;
store/migration/postgres/0.26/01__rename_system_setting_to_instance_setting.sql
0 → 100644
View file @
d326c710
ALTER
TABLE
system_setting
RENAME
TO
instance_setting
;
store/migration/postgres/LATEST.sql
View file @
d326c710
--
system
_setting
--
instance
_setting
CREATE
TABLE
system
_setting
(
CREATE
TABLE
instance
_setting
(
name
TEXT
NOT
NULL
PRIMARY
KEY
,
name
TEXT
NOT
NULL
PRIMARY
KEY
,
value
TEXT
NOT
NULL
,
value
TEXT
NOT
NULL
,
description
TEXT
NOT
NULL
description
TEXT
NOT
NULL
...
@@ -58,8 +58,8 @@ CREATE TABLE memo_relation (
...
@@ -58,8 +58,8 @@ CREATE TABLE memo_relation (
UNIQUE
(
memo_id
,
related_memo_id
,
type
)
UNIQUE
(
memo_id
,
related_memo_id
,
type
)
);
);
--
resource
--
attachment
CREATE
TABLE
resource
(
CREATE
TABLE
attachment
(
id
SERIAL
PRIMARY
KEY
,
id
SERIAL
PRIMARY
KEY
,
uid
TEXT
NOT
NULL
UNIQUE
,
uid
TEXT
NOT
NULL
UNIQUE
,
creator_id
INTEGER
NOT
NULL
,
creator_id
INTEGER
NOT
NULL
,
...
...
store/migration/sqlite/0.26/00__rename_resource_to_attachment.sql
0 → 100644
View file @
d326c710
ALTER
TABLE
`resource`
RENAME
TO
`attachment`
;
DROP
INDEX
IF
EXISTS
`idx_resource_creator_id`
;
CREATE
INDEX
`idx_attachment_creator_id`
ON
`attachment`
(
`creator_id`
);
DROP
INDEX
IF
EXISTS
`idx_resource_memo_id`
;
CREATE
INDEX
`idx_attachment_memo_id`
ON
`attachment`
(
`memo_id`
);
store/migration/sqlite/0.26/01__rename_system_setting_to_instance_setting.sql
0 → 100644
View file @
d326c710
ALTER
TABLE
`system_setting`
RENAME
TO
`instance_setting`
;
store/migration/sqlite/LATEST.sql
View file @
d326c710
--
system
_setting
--
instance
_setting
CREATE
TABLE
system
_setting
(
CREATE
TABLE
instance
_setting
(
name
TEXT
NOT
NULL
,
name
TEXT
NOT
NULL
,
value
TEXT
NOT
NULL
,
value
TEXT
NOT
NULL
,
description
TEXT
NOT
NULL
DEFAULT
''
,
description
TEXT
NOT
NULL
DEFAULT
''
,
...
@@ -63,8 +63,8 @@ CREATE TABLE memo_relation (
...
@@ -63,8 +63,8 @@ CREATE TABLE memo_relation (
UNIQUE
(
memo_id
,
related_memo_id
,
type
)
UNIQUE
(
memo_id
,
related_memo_id
,
type
)
);
);
--
resource
--
attachment
CREATE
TABLE
resource
(
CREATE
TABLE
attachment
(
id
INTEGER
PRIMARY
KEY
AUTOINCREMENT
,
id
INTEGER
PRIMARY
KEY
AUTOINCREMENT
,
uid
TEXT
NOT
NULL
UNIQUE
,
uid
TEXT
NOT
NULL
UNIQUE
,
creator_id
INTEGER
NOT
NULL
,
creator_id
INTEGER
NOT
NULL
,
...
@@ -80,9 +80,9 @@ CREATE TABLE resource (
...
@@ -80,9 +80,9 @@ CREATE TABLE resource (
payload
TEXT
NOT
NULL
DEFAULT
'{}'
payload
TEXT
NOT
NULL
DEFAULT
'{}'
);
);
CREATE
INDEX
idx_
resource_creator_id
ON
resource
(
creator_id
);
CREATE
INDEX
idx_
attachment_creator_id
ON
attachment
(
creator_id
);
CREATE
INDEX
idx_
resource_memo_id
ON
resource
(
memo_id
);
CREATE
INDEX
idx_
attachment_memo_id
ON
attachment
(
memo_id
);
-- activity
-- activity
CREATE
TABLE
activity
(
CREATE
TABLE
activity
(
...
...
store/seed/sqlite/00__reset.sql
deleted
100644 → 0
View file @
01669685
DELETE
FROM
system_setting
;
DELETE
FROM
user
;
DELETE
FROM
user_setting
;
DELETE
FROM
memo
;
DELETE
FROM
memo_organizer
;
DELETE
FROM
memo_relation
;
DELETE
FROM
resource
;
DELETE
FROM
activity
;
DELETE
FROM
idp
;
DELETE
FROM
inbox
;
DELETE
FROM
reaction
;
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