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

feat: organization #3

Merged
merged 10 commits into from
Dec 11, 2023
Merged
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
23 changes: 0 additions & 23 deletions @api/database/migrations/0000_complete_big_bertha.sql

This file was deleted.

64 changes: 64 additions & 0 deletions @api/database/migrations/0000_moaning_toad_men.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
CREATE EXTENSION IF NOT EXISTS "pg_uuidv7";

DO $$ BEGIN
CREATE TYPE "organization_member_roles" AS ENUM('admin', 'member');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "email_otps" (
"email" varchar(255) PRIMARY KEY NOT NULL,
"code" varchar(6) NOT NULL,
"expired_at" timestamp NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "oauth_accounts" (
"provider" varchar(255) NOT NULL,
"provider_user_id" varchar(255) NOT NULL,
"user_id" uuid NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT oauth_accounts_provider_provider_user_id_pk PRIMARY KEY("provider","provider_user_id")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "organization_members" (
"organization_id" uuid NOT NULL,
"user_id" uuid NOT NULL,
"role" "organization_member_roles" DEFAULT 'member' NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT organization_members_organization_id_user_id_pk PRIMARY KEY("organization_id","user_id")
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "organizations" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"name" varchar(255) NOT NULL,
"logo_url" varchar(2550) NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
CREATE TABLE IF NOT EXISTS "users" (
"id" uuid PRIMARY KEY DEFAULT uuid_generate_v7() NOT NULL,
"name" varchar(255) NOT NULL,
"email" varchar(255) NOT NULL,
"avatar_url" varchar(2550) NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL,
CONSTRAINT "users_email_unique" UNIQUE("email")
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "oauth_accounts" ADD CONSTRAINT "oauth_accounts_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "organization_members" ADD CONSTRAINT "organization_members_organization_id_organizations_id_fk" FOREIGN KEY ("organization_id") REFERENCES "organizations"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "organization_members" ADD CONSTRAINT "organization_members_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "users"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;
13 changes: 0 additions & 13 deletions @api/database/migrations/0001_safe_stepford_cuckoos.sql

This file was deleted.

164 changes: 154 additions & 10 deletions @api/database/migrations/meta/0000_snapshot.json
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
{
"id": "203b607f-e416-4a49-8909-d6f918e79161",
"id": "4a71e5fc-5636-4250-8fa6-b48c533e7d1c",
"prevId": "00000000-0000-0000-0000-000000000000",
"version": "5",
"dialect": "pg",
"tables": {
"user_login_otps": {
"name": "user_login_otps",
"email_otps": {
"name": "email_otps",
"schema": "",
"columns": {
"user_id": {
"name": "user_id",
"type": "uuid",
"email": {
"name": "email",
"type": "varchar(255)",
"primaryKey": true,
"notNull": true
},
Expand All @@ -35,17 +35,153 @@
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"oauth_accounts": {
"name": "oauth_accounts",
"schema": "",
"columns": {
"provider": {
"name": "provider",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"provider_user_id": {
"name": "provider_user_id",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"user_login_otps_user_id_users_id_fk": {
"name": "user_login_otps_user_id_users_id_fk",
"tableFrom": "user_login_otps",
"oauth_accounts_user_id_users_id_fk": {
"name": "oauth_accounts_user_id_users_id_fk",
"tableFrom": "oauth_accounts",
"tableTo": "users",
"columnsFrom": ["user_id"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"oauth_accounts_provider_provider_user_id_pk": {
"name": "oauth_accounts_provider_provider_user_id_pk",
"columns": ["provider", "provider_user_id"]
}
},
"uniqueConstraints": {}
},
"organization_members": {
"name": "organization_members",
"schema": "",
"columns": {
"organization_id": {
"name": "organization_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"role": {
"name": "role",
"type": "organization_member_roles",
"primaryKey": false,
"notNull": true,
"default": "'member'"
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"organization_members_organization_id_organizations_id_fk": {
"name": "organization_members_organization_id_organizations_id_fk",
"tableFrom": "organization_members",
"tableTo": "organizations",
"columnsFrom": ["organization_id"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
},
"organization_members_user_id_users_id_fk": {
"name": "organization_members_user_id_users_id_fk",
"tableFrom": "organization_members",
"tableTo": "users",
"columnsFrom": ["user_id"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {
"organization_members_organization_id_user_id_pk": {
"name": "organization_members_organization_id_user_id_pk",
"columns": ["organization_id", "user_id"]
}
},
"uniqueConstraints": {}
},
"organizations": {
"name": "organizations",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "uuid",
"primaryKey": true,
"notNull": true,
"default": "uuid_generate_v7()"
},
"name": {
"name": "name",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"logo_url": {
"name": "logo_url",
"type": "varchar(2550)",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
Expand Down Expand Up @@ -98,7 +234,15 @@
}
}
},
"enums": {},
"enums": {
"organization_member_roles": {
"name": "organization_member_roles",
"values": {
"admin": "admin",
"member": "member"
}
}
},
"schemas": {},
"_meta": {
"schemas": {},
Expand Down
Loading
Loading