From 99bfb1a979dbdb914e54320c860565cc2c82f1b8 Mon Sep 17 00:00:00 2001 From: Alw3ys Date: Tue, 9 Jan 2024 21:03:23 +0100 Subject: [PATCH] deployments and domains --- doseid/migrations/0002_projects.sql | 20 ++++++++++- doseid/src/schema.rs | 51 +++++++++++++++++++++++++++++ 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/doseid/migrations/0002_projects.sql b/doseid/migrations/0002_projects.sql index 3f121109..d4d5413c 100644 --- a/doseid/migrations/0002_projects.sql +++ b/doseid/migrations/0002_projects.sql @@ -16,11 +16,29 @@ CREATE TYPE deployment_status AS ENUM ('queued', 'building', 'error', 'canceled' CREATE TABLE IF NOT EXISTS deployments ( id UUID NOT NULL, - value TEXT NOT NULL, + commit_id TEXT NOT NULL, + commit_metadata jsonb NOT NULL, project_id UUID NOT NULL, owner_id UUID NOT NULL, status deployment_status NOT NULL, + build_logs jsonb NOT NULL, updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, PRIMARY KEY (id) ); + +CREATE TYPE service_type AS ENUM ('project', 'storage'); + +CREATE TABLE IF NOT EXISTS domains ( + id UUID NOT NULL, + name TEXT NOT NULL, + service_type service_type NOT NULL, + project_id UUID, + storage_id UUID, + deployment_id TEXT, + owner_id UUID NOT NULL, + updated_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, + created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP NOT NULL, + PRIMARY KEY (id), + UNIQUE (name) +); diff --git a/doseid/src/schema.rs b/doseid/src/schema.rs index c95db4eb..daf9dcc6 100644 --- a/doseid/src/schema.rs +++ b/doseid/src/schema.rs @@ -56,3 +56,54 @@ pub struct Project { pub updated_at: DateTime, pub created_at: DateTime, } + +#[derive(sqlx::Type, Serialize, Deserialize, Debug)] +#[sqlx(type_name = "status", rename_all = "lowercase")] +pub enum DeploymentStatus { + Queued, + Building, + Error, + Canceled, + Ready, +} + +pub struct Deployment { + pub id: Uuid, + pub commit_id: String, + pub commit_metadata: Value, + pub project_id: Uuid, + pub owner_id: Uuid, + pub status: DeploymentStatus, + pub updated_at: DateTime, + pub created_at: DateTime, +} + +#[derive(sqlx::Type, Serialize, Deserialize, Debug)] +#[sqlx(type_name = "service_type", rename_all = "lowercase")] +pub enum ServiceType { + Queued, + Building, + Error, + Canceled, + Ready, +} + +#[derive(Serialize, Deserialize, Debug)] +pub struct Domain { + pub id: Uuid, + pub name: String, + pub service_type: ServiceType, + pub project_id: Option, + pub storage_id: Option, + pub deployment_id: Option, + pub owner_id: Uuid, + pub updated_at: DateTime, + pub created_at: DateTime, +} + +impl Domain { + pub fn new(mut domain: Domain) -> Domain { + domain.name = domain.name.to_lowercase(); + domain + } +}