-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: add repo owner and separate lfs data for each repository
Add repository owner
- Loading branch information
1 parent
3a61783
commit ea6b9a4
Showing
25 changed files
with
307 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package migrate | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/charmbracelet/soft-serve/server/db" | ||
) | ||
|
||
const ( | ||
repoOwnerName = "repo owner" | ||
repoOwnerVersion = 4 | ||
) | ||
|
||
var repoOwner = Migration{ | ||
Version: repoOwnerVersion, | ||
Name: repoOwnerName, | ||
Migrate: func(ctx context.Context, tx *db.Tx) error { | ||
return migrateUp(ctx, tx, repoOwnerVersion, repoOwnerName) | ||
}, | ||
Rollback: func(ctx context.Context, tx *db.Tx) error { | ||
return migrateDown(ctx, tx, repoOwnerVersion, repoOwnerName) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ALTER TABLE repos DROP COLUMN user_id; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
ALTER TABLE repos ADD COLUMN user_id INTEGER; | ||
|
||
UPDATE repos SET user_id = ( | ||
SELECT id FROM users WHERE admin = true ORDER BY id LIMIT 1 | ||
); | ||
|
||
ALTER TABLE repos | ||
ALTER COLUMN user_id SET NOT NULL; | ||
|
||
ALTER TABLE repos | ||
ADD CONSTRAINT user_id_fk | ||
FOREIGN KEY(user_id) REFERENCES users(id) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP TABLE IF EXISTS repos_old; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
ALTER TABLE repos RENAME TO repos_old; | ||
|
||
CREATE TABLE repos ( | ||
id INTEGER PRIMARY KEY AUTOINCREMENT, | ||
name TEXT NOT NULL UNIQUE, | ||
project_name TEXT NOT NULL, | ||
description TEXT NOT NULL, | ||
private BOOLEAN NOT NULL, | ||
mirror BOOLEAN NOT NULL, | ||
hidden BOOLEAN NOT NULL, | ||
user_id INTEGER NOT NULL, | ||
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
updated_at DATETIME NOT NULL, | ||
CONSTRAINT user_id_fk | ||
FOREIGN KEY(user_id) REFERENCES users(id) | ||
ON DELETE CASCADE | ||
ON UPDATE CASCADE | ||
); | ||
|
||
INSERT INTO repos (id, name, project_name, description, private, mirror, hidden, user_id, created_at, updated_at) | ||
SELECT id, name, project_name, description, private, mirror, hidden, ( | ||
SELECT id FROM users WHERE admin = true ORDER BY id LIMIT 1 | ||
), created_at, updated_at | ||
FROM repos_old; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.