feature: move folders
This commit is contained in:
@@ -192,6 +192,34 @@ func (r *Repository) MoveDocument(ctx context.Context, input MoveDocumentInput)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Repository) MoveFolderRelated(ctx context.Context, oldPrefix, newPrefix string) error {
|
||||
tx, err := r.db.BeginTx(ctx, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("begin folder metadata move: %w", err)
|
||||
}
|
||||
defer func() { _ = tx.Rollback() }()
|
||||
|
||||
if _, err := tx.ExecContext(ctx, `
|
||||
UPDATE permissions
|
||||
SET resource_id = ? || substr(resource_id, length(?) + 1)
|
||||
WHERE resource_type = 'folder' AND (resource_id = ? OR resource_id LIKE ? || '/%')
|
||||
`, newPrefix, oldPrefix, oldPrefix, oldPrefix); err != nil {
|
||||
return fmt.Errorf("move folder permissions: %w", err)
|
||||
}
|
||||
if _, err := tx.ExecContext(ctx, `
|
||||
UPDATE OR IGNORE watchers
|
||||
SET folder_path = ? || substr(folder_path, length(?) + 1)
|
||||
WHERE folder_path IS NOT NULL AND folder_path != '' AND (folder_path = ? OR folder_path LIKE ? || '/%')
|
||||
`, newPrefix, oldPrefix, oldPrefix, oldPrefix); err != nil {
|
||||
return fmt.Errorf("move folder watchers: %w", err)
|
||||
}
|
||||
|
||||
if err := tx.Commit(); err != nil {
|
||||
return fmt.Errorf("commit folder metadata move: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *Repository) GetDocumentByID(ctx context.Context, id string) (*DocumentRecord, error) {
|
||||
var (
|
||||
record DocumentRecord
|
||||
|
||||
Reference in New Issue
Block a user