Skip to content

Commit 6484ee8

Browse files
committed
feat: add domains, update to pg18
1 parent bf433aa commit 6484ee8

File tree

4 files changed

+29
-13
lines changed

4 files changed

+29
-13
lines changed

db/migrations/202504040000000_add_user_tables.sql

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
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
85
CREATE TYPE permission AS ENUM ('Admin', 'Manager', 'User', 'Viewer');
96

107
-- Users Table
118
CREATE 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
3330
CREATE 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
6057
CREATE 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);
7370
CREATE INDEX idx_org_invites_organization_id ON organization_invites(organization_id);
7471
CREATE 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

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ services:
1818
entrypoint: ["crystal", "spec", "-v", "--error-trace"]
1919

2020
postgres:
21-
image: postgres:17-alpine
21+
image: postgres:18-alpine
2222
healthcheck:
2323
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
2424
interval: 30s

shard.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: 2.0
22
shards:
33
action-controller:
44
git: https://github.com/spider-gazelle/action-controller.git
5-
version: 7.6.0
5+
version: 7.6.1
66

77
active-model:
88
git: https://github.com/spider-gazelle/active-model.git
@@ -34,7 +34,7 @@ shards:
3434

3535
hot_topic:
3636
git: https://github.com/jgaskins/hot_topic.git
37-
version: 0.1.0+git.commit.3c901e77b6e000930398738260a2944b6f5785dc
37+
version: 0.1.0+git.commit.4eafc046ed4d98bbab7a4534da57e163ea16b6c6
3838

3939
http-params-serializable:
4040
git: https://github.com/place-labs/http-params-serializable.git
@@ -46,7 +46,7 @@ shards:
4646

4747
lucky_router:
4848
git: https://github.com/luckyframework/lucky_router.git
49-
version: 0.6.0
49+
version: 0.6.1
5050

5151
micrate:
5252
git: https://github.com/amberframework/micrate.git
@@ -66,7 +66,7 @@ shards:
6666

6767
pg-orm:
6868
git: https://github.com/spider-gazelle/pg-orm.git
69-
version: 2.0.3
69+
version: 2.0.5
7070

7171
pool:
7272
git: https://github.com/ysbaddaden/pool.git

src/models/organization.cr

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@ class App::Models::Organization < ::PgORM::Base
88
attribute owner_id : UUID?
99
belongs_to :owner, class_name: User
1010

11+
has_many :domains, class_name: Domain
12+
13+
include PgORM::Timestamps
14+
15+
before_save do
16+
self.name = name.strip
17+
self.description = description.try(&.strip.presence)
18+
end
19+
1120
def users
1221
User.join(:inner, OrganizationUser, :user_id).where("organization_users.organization_id = ?", self.id)
1322
end
@@ -41,6 +50,4 @@ class App::Models::Organization < ::PgORM::Base
4150
expires: expires
4251
).save!
4352
end
44-
45-
include PgORM::Timestamps
4653
end

0 commit comments

Comments
 (0)