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: manage organization members #12

Merged
merged 9 commits into from
Dec 18, 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
14 changes: 14 additions & 0 deletions @api/database/migrations/0001_grey_wiccan.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
CREATE TABLE IF NOT EXISTS "organizations_invitations" (
"id" char(64) PRIMARY KEY NOT NULL,
"organization_id" uuid NOT NULL,
"email" varchar(255) NOT NULL,
"role" "organization_member_roles" DEFAULT 'member' NOT NULL,
"expired_at" timestamp NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
DO $$ BEGIN
ALTER TABLE "organizations_invitations" ADD CONSTRAINT "organizations_invitations_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 $$;
1 change: 1 addition & 0 deletions @api/database/migrations/0002_medical_lilith.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE "organizations_invitations" ADD CONSTRAINT "organizations_invitations_organization_id_email_unique" UNIQUE("organization_id","email");
380 changes: 380 additions & 0 deletions @api/database/migrations/meta/0001_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,380 @@
{
"id": "87cbe321-13e9-4e5f-88f6-a57d14cbd28c",
"prevId": "be57e4a8-c363-4a94-93e7-dba50163ab8b",
"version": "5",
"dialect": "pg",
"tables": {
"email_otps": {
"name": "email_otps",
"schema": "",
"columns": {
"email": {
"name": "email",
"type": "varchar(255)",
"primaryKey": true,
"notNull": true
},
"code": {
"name": "code",
"type": "varchar(6)",
"primaryKey": false,
"notNull": true
},
"expired_at": {
"name": "expired_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"oauth_accounts": {
"name": "oauth_accounts",
"schema": "",
"columns": {
"provider": {
"name": "provider",
"type": "oauth_account_providers",
"primaryKey": false,
"notNull": true
},
"provider_user_id": {
"name": "provider_user_id",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"identifier": {
"name": "identifier",
"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": {
"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": {
"oauth_accounts_provider_user_id_unique": {
"name": "oauth_accounts_provider_user_id_unique",
"nullsNotDistinct": false,
"columns": ["provider", "user_id"]
}
}
},
"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_user_id_organization_id_pk": {
"name": "organization_members_user_id_organization_id_pk",
"columns": ["user_id", "organization_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": {}
},
"organizations_invitations": {
"name": "organizations_invitations",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "char(64)",
"primaryKey": true,
"notNull": true
},
"organization_id": {
"name": "organization_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"email": {
"name": "email",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"role": {
"name": "role",
"type": "organization_member_roles",
"primaryKey": false,
"notNull": true,
"default": "'member'"
},
"expired_at": {
"name": "expired_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"organizations_invitations_organization_id_organizations_id_fk": {
"name": "organizations_invitations_organization_id_organizations_id_fk",
"tableFrom": "organizations_invitations",
"tableTo": "organizations",
"columnsFrom": ["organization_id"],
"columnsTo": ["id"],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"sessions": {
"name": "sessions",
"schema": "",
"columns": {
"id": {
"name": "id",
"type": "char(64)",
"primaryKey": true,
"notNull": true
},
"user_id": {
"name": "user_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"organization_id": {
"name": "organization_id",
"type": "uuid",
"primaryKey": false,
"notNull": true
},
"headers": {
"name": "headers",
"type": "jsonb",
"primaryKey": false,
"notNull": true
},
"created_at": {
"name": "created_at",
"type": "timestamp",
"primaryKey": false,
"notNull": true,
"default": "now()"
}
},
"indexes": {},
"foreignKeys": {
"sessions_user_id_organization_id_fkey": {
"name": "sessions_user_id_organization_id_fkey",
"tableFrom": "sessions",
"tableTo": "organization_members",
"columnsFrom": ["user_id", "organization_id"],
"columnsTo": ["user_id", "organization_id"],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"users": {
"name": "users",
"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
},
"email": {
"name": "email",
"type": "varchar(255)",
"primaryKey": false,
"notNull": true
},
"avatar_url": {
"name": "avatar_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": {
"users_email_unique": {
"name": "users_email_unique",
"nullsNotDistinct": false,
"columns": ["email"]
}
}
}
},
"enums": {
"oauth_account_providers": {
"name": "oauth_account_providers",
"values": {
"github": "github",
"google": "google"
}
},
"organization_member_roles": {
"name": "organization_member_roles",
"values": {
"admin": "admin",
"member": "member"
}
}
},
"schemas": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}
Loading
Loading