11-- +micrate Up
22-- SQL in section 'Up' is executed when this migration is applied
33
4- -- Enable UUID extension
5- CREATE EXTENSION IF NOT EXISTS " uuid-ossp" ;
6-
74-- Permission Enum
85CREATE TYPE permission AS ENUM (' Admin' , ' Manager' , ' User' , ' Viewer' );
96
107-- Users Table
118CREATE TABLE users (
12- id UUID PRIMARY KEY DEFAULT uuid_generate_v4 (),
9+ id UUID PRIMARY KEY DEFAULT uuidv7 (),
1310 name TEXT NOT NULL ,
1411 email TEXT UNIQUE NOT NULL ,
1512 created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
@@ -31,7 +28,7 @@ CREATE INDEX idx_auth_user_id ON auth(user_id);
3128
3229-- Organizations Table
3330CREATE TABLE organizations (
34- id UUID PRIMARY KEY DEFAULT uuid_generate_v4 (),
31+ id UUID PRIMARY KEY DEFAULT uuidv7 (),
3532 owner_id UUID REFERENCES users(id) ON DELETE SET NULL ,
3633 name TEXT NOT NULL ,
3734 description TEXT ,
@@ -58,7 +55,7 @@ CREATE INDEX idx_org_users_organization_id ON organization_users(organization_id
5855
5956-- OrganizationInvites Table
6057CREATE TABLE organization_invites (
61- id UUID PRIMARY KEY DEFAULT uuid_generate_v4 (),
58+ id UUID PRIMARY KEY DEFAULT uuidv7 (),
6259 organization_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE ,
6360 email TEXT NOT NULL ,
6461 secret TEXT NOT NULL ,
@@ -73,5 +70,17 @@ CREATE INDEX idx_org_invites_email ON organization_invites(email);
7370CREATE INDEX idx_org_invites_organization_id ON organization_invites(organization_id);
7471CREATE INDEX idx_org_invites_expires ON organization_invites(expires);
7572
73+ -- Organisation domains
74+ CREATE TABLE domains (
75+ id UUID PRIMARY KEY DEFAULT uuidv7(),
76+ organization_id UUID NOT NULL REFERENCES organizations(id) ON DELETE CASCADE ,
77+ name TEXT NOT NULL ,
78+ domain TEXT NOT NULL ,
79+ description TEXT ,
80+ created_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
81+ updated_at TIMESTAMP WITH TIME ZONE DEFAULT NOW(),
82+ UNIQUE (domain)
83+ );
84+
7685-- +micrate Down
7786-- SQL section 'Down' is executed when this migration is rolled back
0 commit comments