From 4fd2b613224a972fc0c64d29a3af00b7f6adc2dd Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Fri, 7 Oct 2022 17:23:43 -0500 Subject: [PATCH] WIP --- README.md | 2 +- db/migrations.ts | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 0cf3155..7457861 100644 --- a/README.md +++ b/README.md @@ -14,4 +14,4 @@ This will watch the project directory and restart as necessary. - Authn: https://github.com/dashbitco/mix_phx_gen_auth_demo/blob/auth/README.md - Mail client -- Tokens and IDs? I'd love to use ULIDs or something +- Tokens and IDs? I'd love to use some kind of short identifier (youtube-esque IDs) or something diff --git a/db/migrations.ts b/db/migrations.ts index 7a76bfb..98a5405 100644 --- a/db/migrations.ts +++ b/db/migrations.ts @@ -1,6 +1,6 @@ import { query } from "@/db/mod.ts"; -const id = "id uuid primary key default uuid_generate_v4()"; +const id = "id uuid primary key default generate_ulid()"; interface TableSpec { columns: string[]; @@ -106,6 +106,12 @@ begin; ${dropTables} create extension if not exists "uuid-ossp"; +create extension if not exists "pgcrypto"; + +create or replace function generate_ulid() returns uuid + as $$ + select (lpad(to_hex(floor(extract(epoch from clock_timestamp()) * 1000)::bigint), 12, '0') || encode(gen_random_bytes(10), 'hex'))::uuid; + $$ language sql; ${createTables}