diff --git a/model/repo.go b/model/repo.go index c650e5dd..81a81e74 100644 --- a/model/repo.go +++ b/model/repo.go @@ -22,6 +22,7 @@ type Repo struct { Clone string `json:"clone_url,omitempty" meddler:"repo_clone"` Branch string `json:"default_branch,omitempty" meddler:"repo_branch"` Timeout int64 `json:"timeout,omitempty" meddler:"repo_timeout"` + Visibility string `json:"visibility" meddler:"repo_visibility"` IsPrivate bool `json:"private,omitempty" meddler:"repo_private"` IsTrusted bool `json:"trusted" meddler:"repo_trusted"` IsStarred bool `json:"starred,omitempty" meddler:"-"` diff --git a/store/datastore/ddl/mysql/ddl_gen.go b/store/datastore/ddl/mysql/ddl_gen.go index cc4e9f3b..53ed2ae1 100644 --- a/store/datastore/ddl/mysql/ddl_gen.go +++ b/store/datastore/ddl/mysql/ddl_gen.go @@ -88,6 +88,14 @@ var migrations = []struct { name: "create-index-sender-repos", stmt: createIndexSenderRepos, }, + { + name: "alter-table-add-repo-visibility", + stmt: alterTableAddRepoVisibility, + }, + { + name: "update-table-set-repo-visibility", + stmt: updateTableSetRepoVisibility, + }, } // Migrate performs the database migration. If the migration fails @@ -442,3 +450,19 @@ CREATE TABLE IF NOT EXISTS senders ( var createIndexSenderRepos = ` CREATE INDEX sender_repo_ix ON senders (sender_repo_id); ` + +// +// 013_add_column_repo_visibility.sql +// + +var alterTableAddRepoVisibility = ` +ALTER TABLE repos ADD COLUMN repo_visibility INTEGER +` + +var updateTableSetRepoVisibility = ` +UPDATE repos +SET repo_visibility = CASE + WHEN repo_private = 0 THEN 'public' + ELSE 'private' + END +` diff --git a/store/datastore/ddl/mysql/files/013_add_column_repo_visibility.sql b/store/datastore/ddl/mysql/files/013_add_column_repo_visibility.sql new file mode 100644 index 00000000..eb6e8ac5 --- /dev/null +++ b/store/datastore/ddl/mysql/files/013_add_column_repo_visibility.sql @@ -0,0 +1,11 @@ +-- name: alter-table-add-repo-visibility + +ALTER TABLE repos ADD COLUMN repo_visibility INTEGER + +-- name: update-table-set-repo-visibility + +UPDATE repos +SET repo_visibility = CASE + WHEN repo_private = 0 THEN 'public' + ELSE 'private' + END diff --git a/store/datastore/ddl/postgres/ddl_gen.go b/store/datastore/ddl/postgres/ddl_gen.go index c06a2d7c..d2f49fdb 100644 --- a/store/datastore/ddl/postgres/ddl_gen.go +++ b/store/datastore/ddl/postgres/ddl_gen.go @@ -88,6 +88,14 @@ var migrations = []struct { name: "create-index-sender-repos", stmt: createIndexSenderRepos, }, + { + name: "alter-table-add-repo-visibility", + stmt: alterTableAddRepoVisibility, + }, + { + name: "update-table-set-repo-visibility", + stmt: updateTableSetRepoVisibility, + }, } // Migrate performs the database migration. If the migration fails @@ -150,7 +158,7 @@ func selectCompleted(db *sql.DB) (map[string]struct{}, error) { var migrationTableCreate = ` CREATE TABLE IF NOT EXISTS migrations ( - name VARCHAR(512) + name VARCHAR(255) ,UNIQUE(name) ) ` @@ -442,3 +450,19 @@ CREATE TABLE IF NOT EXISTS senders ( var createIndexSenderRepos = ` CREATE INDEX IF NOT EXISTS sender_repo_ix ON senders (sender_repo_id); ` + +// +// 013_add_column_repo_visibility.sql +// + +var alterTableAddRepoVisibility = ` +ALTER TABLE repos ADD COLUMN repo_visibility INTEGER +` + +var updateTableSetRepoVisibility = ` +UPDATE repos +SET repo_visibility = (CASE + WHEN repo_private = 0 THEN 'public' + ELSE 'private' + END) +` diff --git a/store/datastore/ddl/postgres/files/013_add_column_repo_visibility.sql b/store/datastore/ddl/postgres/files/013_add_column_repo_visibility.sql new file mode 100644 index 00000000..109d79df --- /dev/null +++ b/store/datastore/ddl/postgres/files/013_add_column_repo_visibility.sql @@ -0,0 +1,11 @@ +-- name: alter-table-add-repo-visibility + +ALTER TABLE repos ADD COLUMN repo_visibility INTEGER + +-- name: update-table-set-repo-visibility + +UPDATE repos +SET repo_visibility = (CASE + WHEN repo_private = 0 THEN 'public' + ELSE 'private' + END) diff --git a/store/datastore/ddl/sqlite/ddl_gen.go b/store/datastore/ddl/sqlite/ddl_gen.go index d00be514..ab3bd263 100644 --- a/store/datastore/ddl/sqlite/ddl_gen.go +++ b/store/datastore/ddl/sqlite/ddl_gen.go @@ -92,6 +92,14 @@ var migrations = []struct { name: "create-index-sender-repos", stmt: createIndexSenderRepos, }, + { + name: "alter-table-add-repo-visibility", + stmt: alterTableAddRepoVisibility, + }, + { + name: "update-table-set-repo-visibility", + stmt: updateTableSetRepoVisibility, + }, } // Migrate performs the database migration. If the migration fails @@ -154,7 +162,7 @@ func selectCompleted(db *sql.DB) (map[string]struct{}, error) { var migrationTableCreate = ` CREATE TABLE IF NOT EXISTS migrations ( - name VARCHAR(512) + name VARCHAR(255) ,UNIQUE(name) ) ` @@ -443,3 +451,19 @@ CREATE TABLE IF NOT EXISTS senders ( var createIndexSenderRepos = ` CREATE INDEX IF NOT EXISTS sender_repo_ix ON senders (sender_repo_id); ` + +// +// 013_add_column_repo_visibility.sql +// + +var alterTableAddRepoVisibility = ` +ALTER TABLE repos ADD COLUMN repo_visibility INTEGER +` + +var updateTableSetRepoVisibility = ` +UPDATE repos +SET repo_visibility = CASE + WHEN repo_private = 0 THEN 'public' + ELSE 'private' + END +` diff --git a/store/datastore/ddl/sqlite/files/013_add_column_repo_visibility.sql b/store/datastore/ddl/sqlite/files/013_add_column_repo_visibility.sql new file mode 100644 index 00000000..eb6e8ac5 --- /dev/null +++ b/store/datastore/ddl/sqlite/files/013_add_column_repo_visibility.sql @@ -0,0 +1,11 @@ +-- name: alter-table-add-repo-visibility + +ALTER TABLE repos ADD COLUMN repo_visibility INTEGER + +-- name: update-table-set-repo-visibility + +UPDATE repos +SET repo_visibility = CASE + WHEN repo_private = 0 THEN 'public' + ELSE 'private' + END