mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-12 04:15:30 +00:00
migrate to using enums for connectionType and external_codeHostType
This commit is contained in:
parent
4899c9fbc7
commit
94877debc1
3 changed files with 65 additions and 2 deletions
|
|
@ -0,0 +1,14 @@
|
||||||
|
/*
|
||||||
|
Migrates the `connectionType` column from text to a enum. The values in this field are known to
|
||||||
|
be one of the following: github, gitlab, gitea, gerrit, bitbucket, azuredevops, git.
|
||||||
|
|
||||||
|
This is occording to what we would expect to be in a valid config file for the schema version at commit 4899c9fbc755851af2ddcce99f4a4200f2faa4f6.
|
||||||
|
See: https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/schemas/src/v3/connection.type.ts#L3
|
||||||
|
*/
|
||||||
|
-- CreateEnum
|
||||||
|
CREATE TYPE "ConnectionType" AS ENUM ('github', 'gitlab', 'gitea', 'gerrit', 'bitbucket', 'azuredevops', 'git');
|
||||||
|
|
||||||
|
-- AlterTable - Convert existing column to enum type without dropping data
|
||||||
|
ALTER TABLE "Connection"
|
||||||
|
ALTER COLUMN "connectionType" TYPE "ConnectionType"
|
||||||
|
USING "connectionType"::text::"ConnectionType";
|
||||||
|
|
@ -0,0 +1,22 @@
|
||||||
|
/*
|
||||||
|
Migrates the `external_codeHostType` column from text to a enum. The values in this field are known to
|
||||||
|
be one of the following: github, gitlab, gitea, gerrit, bitbucket-server, bitbucket-cloud, generic-git-host, azuredevops.
|
||||||
|
|
||||||
|
This is occording to what we would expect to be in the database written as of commit 4899c9fbc755851af2ddcce99f4a4200f2faa4f6.
|
||||||
|
See:
|
||||||
|
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L57
|
||||||
|
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L135
|
||||||
|
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L208
|
||||||
|
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L291
|
||||||
|
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L407
|
||||||
|
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L510
|
||||||
|
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L574
|
||||||
|
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L642
|
||||||
|
*/
|
||||||
|
-- CreateEnum
|
||||||
|
CREATE TYPE "CodeHostType" AS ENUM ('github', 'gitlab', 'gitea', 'gerrit', 'bitbucket-server', 'bitbucket-cloud', 'generic-git-host', 'azuredevops');
|
||||||
|
|
||||||
|
-- AlterTable - Convert existing column to enum type without dropping data
|
||||||
|
ALTER TABLE "Repo"
|
||||||
|
ALTER COLUMN "external_codeHostType" TYPE "CodeHostType"
|
||||||
|
USING "external_codeHostType"::text::"CodeHostType";
|
||||||
|
|
@ -29,6 +29,21 @@ enum ChatVisibility {
|
||||||
PUBLIC
|
PUBLIC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// @note: The @map annotation is required to maintain backwards compatibility
|
||||||
|
/// with the existing database.
|
||||||
|
/// @note: In the generated client, these mapped values will be in pascalCase.
|
||||||
|
/// This behaviour will change in prisma v7. See: https://github.com/prisma/prisma/issues/8446#issuecomment-3356119713
|
||||||
|
enum CodeHostType {
|
||||||
|
github
|
||||||
|
gitlab
|
||||||
|
gitea
|
||||||
|
gerrit
|
||||||
|
bitbucketServer @map("bitbucket-server")
|
||||||
|
bitbucketCloud @map("bitbucket-cloud")
|
||||||
|
genericGitHost @map("generic-git-host")
|
||||||
|
azuredevops
|
||||||
|
}
|
||||||
|
|
||||||
model Repo {
|
model Repo {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
name String /// Full repo name, including the vcs hostname (ex. github.com/sourcebot-dev/sourcebot)
|
name String /// Full repo name, including the vcs hostname (ex. github.com/sourcebot-dev/sourcebot)
|
||||||
|
|
@ -53,7 +68,7 @@ model Repo {
|
||||||
indexedCommitHash String? /// The commit hash of the last indexed commit (on HEAD).
|
indexedCommitHash String? /// The commit hash of the last indexed commit (on HEAD).
|
||||||
|
|
||||||
external_id String /// The id of the repo in the external service
|
external_id String /// The id of the repo in the external service
|
||||||
external_codeHostType String /// The type of the external service (e.g., github, gitlab, etc.)
|
external_codeHostType CodeHostType /// The type of the external service (e.g., github, gitlab, etc.)
|
||||||
external_codeHostUrl String /// The base url of the external service (e.g., https://github.com)
|
external_codeHostUrl String /// The base url of the external service (e.g., https://github.com)
|
||||||
|
|
||||||
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
|
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
|
||||||
|
|
@ -125,6 +140,18 @@ model SearchContext {
|
||||||
@@unique([name, orgId])
|
@@unique([name, orgId])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Matches the union of `type` fields in the schema.
|
||||||
|
/// @see: schemas/v3/connection.type.ts
|
||||||
|
enum ConnectionType {
|
||||||
|
github
|
||||||
|
gitlab
|
||||||
|
gitea
|
||||||
|
gerrit
|
||||||
|
bitbucket
|
||||||
|
azuredevops
|
||||||
|
git
|
||||||
|
}
|
||||||
|
|
||||||
model Connection {
|
model Connection {
|
||||||
id Int @id @default(autoincrement())
|
id Int @id @default(autoincrement())
|
||||||
name String
|
name String
|
||||||
|
|
@ -135,7 +162,7 @@ model Connection {
|
||||||
repos RepoToConnection[]
|
repos RepoToConnection[]
|
||||||
|
|
||||||
// The type of connection (e.g., github, gitlab, etc.)
|
// The type of connection (e.g., github, gitlab, etc.)
|
||||||
connectionType String
|
connectionType ConnectionType
|
||||||
|
|
||||||
syncJobs ConnectionSyncJob[]
|
syncJobs ConnectionSyncJob[]
|
||||||
/// When the connection was last synced successfully.
|
/// When the connection was last synced successfully.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue