feat - New profile table connected to the authenticated user base
This commit is contained in:
parent
c0764fcc84
commit
970c8b33db
@ -1,5 +1,5 @@
|
||||
import { defineConfig } from 'drizzle-kit';
|
||||
console.log(process.env.DATABASE_URL)
|
||||
|
||||
export default defineConfig({
|
||||
schema: './src/integrations/drizzle/db/schema.ts',
|
||||
out: './src/integrations/supabase/migrations',
|
||||
|
||||
@ -1,6 +1,44 @@
|
||||
import { pgTable, serial, text, varchar } from "drizzle-orm/pg-core";
|
||||
|
||||
|
||||
|
||||
import { sql } from 'drizzle-orm';
|
||||
import { foreignKey, pgPolicy, pgTable, serial, text, uuid, varchar } from 'drizzle-orm/pg-core';
|
||||
import { authenticatedRole, authUsers } from 'drizzle-orm/supabase';
|
||||
|
||||
export const users = pgTable('demo', {
|
||||
id: serial('id').primaryKey(),
|
||||
fullName: text('full_name'),
|
||||
phone: varchar('phone', { length: 256 }),
|
||||
});
|
||||
phone: varchar('phone', { length: 256 })
|
||||
});
|
||||
|
||||
export const profiles = pgTable(
|
||||
'profiles',
|
||||
{
|
||||
id: uuid('id').notNull().primaryKey(),
|
||||
firstName: text('first_name'),
|
||||
lastName: text('last_name'),
|
||||
},
|
||||
(table) => [
|
||||
foreignKey({
|
||||
columns: [table.id],
|
||||
foreignColumns: [authUsers.id],
|
||||
name: 'profiles_id_fkey',
|
||||
}).onDelete('cascade'),
|
||||
pgPolicy('select-own-profile', {
|
||||
for: 'select',
|
||||
to: authenticatedRole,
|
||||
using: sql`${table.id} = auth.uid()`,
|
||||
}),
|
||||
pgPolicy('update-own-profile', {
|
||||
for: 'update',
|
||||
to: authenticatedRole,
|
||||
using: sql`${table.id} = auth.uid()`,
|
||||
withCheck: sql`${table.id} = auth.uid()`,
|
||||
}),
|
||||
pgPolicy('insert-profile', {
|
||||
for: 'insert',
|
||||
to: authenticatedRole,
|
||||
withCheck: sql`${table.id} = auth.uid()`,
|
||||
})
|
||||
]
|
||||
).enableRLS();
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
CREATE TABLE "demo" (
|
||||
IF NOT EXISTS CREATE TABLE "demo" (
|
||||
"id" serial PRIMARY KEY NOT NULL,
|
||||
"full_name" text,
|
||||
"phone" varchar(256)
|
||||
|
||||
11
src/integrations/supabase/migrations/0001_nice_gargoyle.sql
Normal file
11
src/integrations/supabase/migrations/0001_nice_gargoyle.sql
Normal file
@ -0,0 +1,11 @@
|
||||
CREATE TABLE "profiles" (
|
||||
"id" uuid PRIMARY KEY NOT NULL,
|
||||
"first_name" text,
|
||||
"last_name" text
|
||||
);
|
||||
--> statement-breakpoint
|
||||
ALTER TABLE "profiles" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint
|
||||
ALTER TABLE "profiles" ADD CONSTRAINT "profiles_id_fkey" FOREIGN KEY ("id") REFERENCES "auth"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
||||
CREATE POLICY "select-own-profile" ON "profiles" AS PERMISSIVE FOR SELECT TO "authenticated" USING ("profiles"."id" = auth.uid());--> statement-breakpoint
|
||||
CREATE POLICY "update-own-profile" ON "profiles" AS PERMISSIVE FOR UPDATE TO "authenticated" USING ("profiles"."id" = auth.uid()) WITH CHECK ("profiles"."id" = auth.uid());--> statement-breakpoint
|
||||
CREATE POLICY "insert-profile" ON "profiles" AS PERMISSIVE FOR INSERT TO "authenticated" WITH CHECK ("profiles"."id" = auth.uid());
|
||||
125
src/integrations/supabase/migrations/meta/0001_snapshot.json
Normal file
125
src/integrations/supabase/migrations/meta/0001_snapshot.json
Normal file
@ -0,0 +1,125 @@
|
||||
{
|
||||
"id": "7d0d4272-65ba-45cf-9dd3-a5e2008d3744",
|
||||
"prevId": "c266fe94-b863-4b6c-930c-44af8af68c1a",
|
||||
"version": "7",
|
||||
"dialect": "postgresql",
|
||||
"tables": {
|
||||
"public.profiles": {
|
||||
"name": "profiles",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "uuid",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"first_name": {
|
||||
"name": "first_name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"last_name": {
|
||||
"name": "last_name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {
|
||||
"profiles_id_fkey": {
|
||||
"name": "profiles_id_fkey",
|
||||
"tableFrom": "profiles",
|
||||
"tableTo": "users",
|
||||
"schemaTo": "auth",
|
||||
"columnsFrom": [
|
||||
"id"
|
||||
],
|
||||
"columnsTo": [
|
||||
"id"
|
||||
],
|
||||
"onDelete": "cascade",
|
||||
"onUpdate": "no action"
|
||||
}
|
||||
},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"policies": {
|
||||
"select-own-profile": {
|
||||
"name": "select-own-profile",
|
||||
"as": "PERMISSIVE",
|
||||
"for": "SELECT",
|
||||
"to": [
|
||||
"authenticated"
|
||||
],
|
||||
"using": "\"profiles\".\"id\" = auth.uid()"
|
||||
},
|
||||
"update-own-profile": {
|
||||
"name": "update-own-profile",
|
||||
"as": "PERMISSIVE",
|
||||
"for": "UPDATE",
|
||||
"to": [
|
||||
"authenticated"
|
||||
],
|
||||
"using": "\"profiles\".\"id\" = auth.uid()",
|
||||
"withCheck": "\"profiles\".\"id\" = auth.uid()"
|
||||
},
|
||||
"insert-profile": {
|
||||
"name": "insert-profile",
|
||||
"as": "PERMISSIVE",
|
||||
"for": "INSERT",
|
||||
"to": [
|
||||
"authenticated"
|
||||
],
|
||||
"withCheck": "\"profiles\".\"id\" = auth.uid()"
|
||||
}
|
||||
},
|
||||
"checkConstraints": {},
|
||||
"isRLSEnabled": true
|
||||
},
|
||||
"public.demo": {
|
||||
"name": "demo",
|
||||
"schema": "",
|
||||
"columns": {
|
||||
"id": {
|
||||
"name": "id",
|
||||
"type": "serial",
|
||||
"primaryKey": true,
|
||||
"notNull": true
|
||||
},
|
||||
"full_name": {
|
||||
"name": "full_name",
|
||||
"type": "text",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
},
|
||||
"phone": {
|
||||
"name": "phone",
|
||||
"type": "varchar(256)",
|
||||
"primaryKey": false,
|
||||
"notNull": false
|
||||
}
|
||||
},
|
||||
"indexes": {},
|
||||
"foreignKeys": {},
|
||||
"compositePrimaryKeys": {},
|
||||
"uniqueConstraints": {},
|
||||
"policies": {},
|
||||
"checkConstraints": {},
|
||||
"isRLSEnabled": false
|
||||
}
|
||||
},
|
||||
"enums": {},
|
||||
"schemas": {},
|
||||
"sequences": {},
|
||||
"roles": {},
|
||||
"policies": {},
|
||||
"views": {},
|
||||
"_meta": {
|
||||
"columns": {},
|
||||
"schemas": {},
|
||||
"tables": {}
|
||||
}
|
||||
}
|
||||
@ -8,6 +8,13 @@
|
||||
"when": 1754932713212,
|
||||
"tag": "0000_talented_doorman",
|
||||
"breakpoints": true
|
||||
},
|
||||
{
|
||||
"idx": 1,
|
||||
"version": "7",
|
||||
"when": 1755013739316,
|
||||
"tag": "0001_nice_gargoyle",
|
||||
"breakpoints": true
|
||||
}
|
||||
]
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user