Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UNIQUE index on VirtualRepo to prevent duplicates #463

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion scripts/sql/mysql/seafile.sql
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ CREATE TABLE IF NOT EXISTS VirtualRepo (
path TEXT,
base_commit CHAR(40),
UNIQUE INDEX(repo_id),
INDEX(origin_repo)
INDEX(origin_repo),
UNIQUE INDEX(origin_repo,path)
) ENGINE=INNODB;

CREATE TABLE IF NOT EXISTS WebAP (
Expand Down
1 change: 1 addition & 0 deletions scripts/sql/sqlite/seafile.sql
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ CREATE TABLE IF NOT EXISTS RepoValidSince (repo_id CHAR(37) PRIMARY KEY, timesta
CREATE TABLE IF NOT EXISTS WebAP (repo_id CHAR(37) PRIMARY KEY, access_property CHAR(10));
CREATE TABLE IF NOT EXISTS VirtualRepo (repo_id CHAR(36) PRIMARY KEY, origin_repo CHAR(36), path TEXT, base_commit CHAR(40));
CREATE INDEX IF NOT EXISTS virtualrepo_origin_repo_idx ON VirtualRepo (origin_repo);
CREATE INDEX IF NOT EXISTS virtualrepo_unique_idx ON VirtualRepo (origin_repo, path);
CREATE TABLE IF NOT EXISTS GarbageRepos (repo_id CHAR(36) PRIMARY KEY);
CREATE TABLE IF NOT EXISTS RepoTrash (repo_id CHAR(36) PRIMARY KEY, repo_name VARCHAR(255), head_id CHAR(40), owner_id VARCHAR(255), size BIGINT UNSIGNED, org_id INTEGER, del_time BIGINT);
CREATE INDEX IF NOT EXISTS repotrash_owner_id_idx ON RepoTrash(owner_id);
Expand Down
1 change: 1 addition & 0 deletions scripts/upgrade/sql/8.1.0/mysql/seafile.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE VirtualRepo ADD UNIQUE INDEX(origin_repo,path);
1 change: 1 addition & 0 deletions scripts/upgrade/sql/8.1.0/sqlite3/seafile.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE INDEX IF NOT EXISTS "virtualrepo_unique_idx" ON "VirtualRepo" ("origin_repo", "path");
9 changes: 7 additions & 2 deletions server/repo-mgr.c
Original file line number Diff line number Diff line change
Expand Up @@ -1039,8 +1039,8 @@ create_tables_mysql (SeafRepoManager *mgr)

sql = "CREATE TABLE IF NOT EXISTS VirtualRepo (id BIGINT NOT NULL PRIMARY KEY AUTO_INCREMENT, "
"repo_id CHAR(36),"
"origin_repo CHAR(36), path TEXT, base_commit CHAR(40), UNIQUE INDEX(repo_id), INDEX(origin_repo))"
"ENGINE=INNODB";
"origin_repo CHAR(36), path TEXT, base_commit CHAR(40), UNIQUE INDEX(repo_id), INDEX(origin_repo)), "
"UNIQUE INDEX(origin_repo,path) ENGINE=INNODB";
if (seaf_db_query (db, sql) < 0)
return -1;

Expand Down Expand Up @@ -1195,6 +1195,11 @@ create_tables_sqlite (SeafRepoManager *mgr)
if (seaf_db_query (db, sql) < 0)
return -1;

sql = "CREATE INDEX IF NOT EXISTS virtualrepo_unique_idx "
"ON VirtualRepo (origin_repo, path)";
if (seaf_db_query (db, sql) < 0)
return -1;

sql = "CREATE TABLE IF NOT EXISTS GarbageRepos (repo_id CHAR(36) PRIMARY KEY)";
if (seaf_db_query (db, sql) < 0)
return -1;
Expand Down