From 2b54cc229506275312afa63d4516443da07ad610 Mon Sep 17 00:00:00 2001 From: Charles Taylor Date: Thu, 28 Nov 2024 11:56:00 -0500 Subject: [PATCH] Remove supabase --- deploy.nu | 5 +- src/markup/base.rs | 10 +- supabase/.gitignore | 4 - supabase/config.toml | 134 ------------ .../20240512200629_remote_schema.sql | 206 ------------------ supabase/seed.sql | 1 - upload-assets.js | 63 ------ 7 files changed, 8 insertions(+), 415 deletions(-) delete mode 100644 supabase/.gitignore delete mode 100644 supabase/config.toml delete mode 100644 supabase/migrations/20240512200629_remote_schema.sql delete mode 100644 supabase/seed.sql delete mode 100644 upload-assets.js diff --git a/deploy.nu b/deploy.nu index 40c29c86..b43f832e 100755 --- a/deploy.nu +++ b/deploy.nu @@ -1,11 +1,10 @@ def main [branch: string = "main"] { - let api_key = open .env | get UPLOAD_THING_API_KEY # generate minified stylesheet tailwindcss --input tailwind.source.css --output public/styles/index.css --minify + let api_key = open .env | get UPLOADTHING_API_KEY - # upload assets to supabase cdn - node upload-assets.js + # TODO: upload public dir # deploy to citadels.fly.dev fly secrets set GIT_SHA=$(git show -s --format=%H) diff --git a/src/markup/base.rs b/src/markup/base.rs index 5411e5a6..25ab53a9 100644 --- a/src/markup/base.rs +++ b/src/markup/base.rs @@ -85,9 +85,11 @@ pub fn asset(path: &str) -> String { if cfg!(feature = "dev") { format!("/public/{path}") } else { - format!( - "{}/storage/v1/object/public/assets/{path}", - env::var("SUPABASE_PROJECT_URL").unwrap() - ) + format!("/public/{path}") + // TODO: use uploadthing in production + // format!( + // "{}/storage/v1/object/public/assets/{path}", + // env::var("SUPABASE_PROJECT_URL").unwrap() + // ) } } diff --git a/supabase/.gitignore b/supabase/.gitignore deleted file mode 100644 index a3ad8805..00000000 --- a/supabase/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -# Supabase -.branches -.temp -.env diff --git a/supabase/config.toml b/supabase/config.toml deleted file mode 100644 index 6289a72c..00000000 --- a/supabase/config.toml +++ /dev/null @@ -1,134 +0,0 @@ -# A string used to distinguish different Supabase projects on the same host. Defaults to the -# working directory name when running `supabase init`. -project_id = "citadels" - -[api] -enabled = true -# Port to use for the API URL. -port = 54321 -# Schemas to expose in your API. Tables, views and stored procedures in this schema will get API -# endpoints. `public` is always included. -schemas = ["public", "graphql_public"] -# Extra schemas to add to the search_path of every request. `public` is always included. -extra_search_path = ["public", "extensions"] -# The maximum number of rows returns from a view, table, or stored procedure. Limits payload size -# for accidental or malicious requests. -max_rows = 100 - -[db] -# Port to use for the local database URL. -port = 54322 -# Port used by db diff command to initialize the shadow database. -shadow_port = 54320 -# The database major version to use. This has to be the same as your remote database's. Run `SHOW -# server_version;` on the remote database to check. -major_version = 15 - -[db.pooler] -enabled = false -# Port to use for the local connection pooler. -port = 54329 -# Specifies when a server connection can be reused by other clients. -# Configure one of the supported pooler modes: `transaction`, `session`. -pool_mode = "transaction" -# How many server connections to allow per user/database pair. -default_pool_size = 20 -# Maximum number of client connections allowed. -max_client_conn = 100 - -[realtime] -enabled = true -# Bind realtime via either IPv4 or IPv6. (default: IPv4) -# ip_version = "IPv6" -# The maximum length in bytes of HTTP request headers. (default: 4096) -# max_header_length = 4096 - -[studio] -enabled = true -# Port to use for Supabase Studio. -port = 54323 -# External URL of the API server that frontend connects to. -api_url = "http://127.0.0.1" -# OpenAI API Key to use for Supabase AI in the Supabase Studio. -openai_api_key = "env(OPENAI_API_KEY)" - -# Email testing server. Emails sent with the local dev setup are not actually sent - rather, they -# are monitored, and you can view the emails that would have been sent from the web interface. -[inbucket] -enabled = true -# Port to use for the email testing server web interface. -port = 54324 -# Uncomment to expose additional ports for testing user applications that send emails. -# smtp_port = 54325 -# pop3_port = 54326 - -[storage] -enabled = true -# The maximum file size allowed (e.g. "5MB", "500KB"). -file_size_limit = "50MiB" - -[storage.image_transformation] -enabled = true - -[auth] -enabled = true -# The base URL of your website. Used as an allow-list for redirects and for constructing URLs used -# in emails. -site_url = "http://127.0.0.1:3000" -# A list of *exact* URLs that auth providers are permitted to redirect to post authentication. -additional_redirect_urls = ["https://127.0.0.1:3000"] -# How long tokens are valid for, in seconds. Defaults to 3600 (1 hour), maximum 604,800 (1 week). -jwt_expiry = 3600 -# If disabled, the refresh token will never expire. -enable_refresh_token_rotation = true -# Allows refresh tokens to be reused after expiry, up to the specified interval in seconds. -# Requires enable_refresh_token_rotation = true. -refresh_token_reuse_interval = 10 -# Allow/disallow new user signups to your project. -enable_signup = true -# Allow/disallow anonymous sign-ins to your project. -enable_anonymous_sign_ins = false -# Allow/disallow testing manual linking of accounts -enable_manual_linking = false - -[auth.email] -# Allow/disallow new user signups via email to your project. -enable_signup = true -# If enabled, a user will be required to confirm any email change on both the old, and new email -# addresses. If disabled, only the new email is required to confirm. -double_confirm_changes = true -# If enabled, users need to confirm their email address before signing in. -enable_confirmations = false -# Controls the minimum amount of time that must pass before sending another signup confirmation or password reset email. -max_frequency = "5s" - -# Uncomment to customize email template -# [auth.email.template.invite] -# subject = "You have been invited" -# content_path = "./supabase/templates/invite.html" - -[auth.sms] -# Allow/disallow new user signups via SMS to your project. -enable_signup = true -# If enabled, users need to confirm their phone number before signing in. -enable_confirmations = true -# Template for sending OTP to users -template = "Your code is {{ .Code }} ." -# Controls the minimum amount of time that must pass before sending another sms otp. -max_frequency = "5s" - -# Use pre-defined map of phone number to OTP for testing. -# [auth.sms.test_otp] -# 4152127777 = "123456" - -# This hook runs before a token is issued and allows you to add additional claims based on the authentication method used. -# [auth.hook.custom_access_token] -# enabled = true -# uri = "pg-functions:////" - -[analytics] -enabled = false -port = 54327 -vector_port = 54328 -# supported backends: `postgres`, `bigquery`. -backend = "postgres" diff --git a/supabase/migrations/20240512200629_remote_schema.sql b/supabase/migrations/20240512200629_remote_schema.sql deleted file mode 100644 index c076f0c8..00000000 --- a/supabase/migrations/20240512200629_remote_schema.sql +++ /dev/null @@ -1,206 +0,0 @@ - -SET statement_timeout = 0; -SET lock_timeout = 0; -SET idle_in_transaction_session_timeout = 0; -SET client_encoding = 'UTF8'; -SET standard_conforming_strings = on; -SELECT pg_catalog.set_config('search_path', '', false); -SET check_function_bodies = false; -SET xmloption = content; -SET client_min_messages = warning; -SET row_security = off; - -CREATE EXTENSION IF NOT EXISTS "pg_net" WITH SCHEMA "extensions"; - -CREATE EXTENSION IF NOT EXISTS "pgsodium" WITH SCHEMA "pgsodium"; - -COMMENT ON SCHEMA "public" IS 'standard public schema'; - -CREATE EXTENSION IF NOT EXISTS "pg_graphql" WITH SCHEMA "graphql"; - -CREATE EXTENSION IF NOT EXISTS "pg_stat_statements" WITH SCHEMA "extensions"; - -CREATE EXTENSION IF NOT EXISTS "pgcrypto" WITH SCHEMA "extensions"; - -CREATE EXTENSION IF NOT EXISTS "pgjwt" WITH SCHEMA "extensions"; - -CREATE EXTENSION IF NOT EXISTS "supabase_vault" WITH SCHEMA "vault"; - -CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA "extensions"; - -SET default_tablespace = ''; - -SET default_table_access_method = "heap"; - -CREATE TABLE IF NOT EXISTS "public"."game_districts" ( - "positions" "jsonb" DEFAULT '{}'::"jsonb" NOT NULL, - "game_id" bigint NOT NULL, - "user_id" "uuid" DEFAULT "auth"."uid"() NOT NULL -); - -ALTER TABLE "public"."game_districts" OWNER TO "postgres"; - -CREATE TABLE IF NOT EXISTS "public"."game_hands" ( - "game_id" bigint NOT NULL, - "user_id" "uuid" DEFAULT "auth"."uid"() NOT NULL, - "districts" "text"[] NOT NULL -); - -ALTER TABLE "public"."game_hands" OWNER TO "postgres"; - -CREATE TABLE IF NOT EXISTS "public"."games" ( - "id" bigint NOT NULL, - "state" "jsonb" NOT NULL, - "ended_at" timestamp with time zone, - "started_at" timestamp with time zone DEFAULT "now"() NOT NULL, - "version" bigint NOT NULL -); - -ALTER TABLE "public"."games" OWNER TO "postgres"; - -ALTER TABLE "public"."games" ALTER COLUMN "id" ADD GENERATED BY DEFAULT AS IDENTITY ( - SEQUENCE NAME "public"."games_id_seq" - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1 -); - -CREATE TABLE IF NOT EXISTS "public"."profiles" ( - "user_id" "uuid" DEFAULT "auth"."uid"() NOT NULL, - "created_at" timestamp with time zone DEFAULT "now"() NOT NULL, - "username" character varying NOT NULL -); - -ALTER TABLE "public"."profiles" OWNER TO "postgres"; - -CREATE TABLE IF NOT EXISTS "public"."rooms" ( - "id" "uuid" DEFAULT "gen_random_uuid"() NOT NULL, - "created_at" timestamp with time zone DEFAULT "now"() NOT NULL, - "game_id" bigint, - "game_config" "jsonb" NOT NULL, - "host_id" "uuid" DEFAULT "auth"."uid"() NOT NULL, - "player_ids" "text"[] DEFAULT '{auth.uid()::text}'::"text"[] NOT NULL -); - -ALTER TABLE "public"."rooms" OWNER TO "postgres"; - -ALTER TABLE ONLY "public"."game_districts" - ADD CONSTRAINT "game_districts_pkey" PRIMARY KEY ("game_id", "user_id"); - -ALTER TABLE ONLY "public"."game_hands" - ADD CONSTRAINT "game_hands_pkey" PRIMARY KEY ("game_id", "user_id"); - -ALTER TABLE ONLY "public"."games" - ADD CONSTRAINT "games_pkey" PRIMARY KEY ("id"); - -ALTER TABLE ONLY "public"."profiles" - ADD CONSTRAINT "profiles_pkey" PRIMARY KEY ("user_id"); - -ALTER TABLE ONLY "public"."profiles" - ADD CONSTRAINT "profiles_username_key" UNIQUE ("username"); - -ALTER TABLE ONLY "public"."rooms" - ADD CONSTRAINT "rooms_owner_id_key" UNIQUE ("host_id"); - -ALTER TABLE ONLY "public"."rooms" - ADD CONSTRAINT "rooms_pkey" PRIMARY KEY ("id"); - -ALTER TABLE ONLY "public"."game_districts" - ADD CONSTRAINT "game_districts_game_id_fkey" FOREIGN KEY ("game_id") REFERENCES "public"."games"("id"); - -ALTER TABLE ONLY "public"."game_districts" - ADD CONSTRAINT "game_districts_user_id_fkey1" FOREIGN KEY ("user_id") REFERENCES "public"."profiles"("user_id"); - -ALTER TABLE ONLY "public"."game_hands" - ADD CONSTRAINT "game_hands_game_id_fkey" FOREIGN KEY ("game_id") REFERENCES "public"."games"("id"); - -ALTER TABLE ONLY "public"."game_hands" - ADD CONSTRAINT "game_hands_user_id_fkey1" FOREIGN KEY ("user_id") REFERENCES "public"."profiles"("user_id"); - -ALTER TABLE ONLY "public"."profiles" - ADD CONSTRAINT "profiles_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "auth"."users"("id") ON DELETE CASCADE; - -ALTER TABLE ONLY "public"."rooms" - ADD CONSTRAINT "rooms_game_id_fkey" FOREIGN KEY ("game_id") REFERENCES "public"."games"("id"); - -ALTER TABLE ONLY "public"."rooms" - ADD CONSTRAINT "rooms_host_id_fkey1" FOREIGN KEY ("host_id") REFERENCES "public"."profiles"("user_id"); - -CREATE POLICY "Anyone can view" ON "public"."rooms" AS RESTRICTIVE FOR SELECT USING (true); - -CREATE POLICY "Anyone can view city district positions" ON "public"."game_districts" FOR SELECT USING (true); - -CREATE POLICY "Owner can close room" ON "public"."rooms" FOR DELETE USING (("host_id" = "auth"."uid"())); - -CREATE POLICY "Owner can create room" ON "public"."rooms" FOR INSERT WITH CHECK (("host_id" = "auth"."uid"())); - -CREATE POLICY "Owner can move districts in their city" ON "public"."game_districts" FOR UPDATE USING (("user_id" = "auth"."uid"())); - -CREATE POLICY "Owner can update room ( to kick players)" ON "public"."rooms" AS RESTRICTIVE FOR UPDATE USING (("host_id" = "auth"."uid"())); - -CREATE POLICY "Owner can view their hands" ON "public"."game_hands" FOR SELECT USING (("user_id" = "auth"."uid"())); - -ALTER TABLE "public"."game_districts" ENABLE ROW LEVEL SECURITY; - -ALTER TABLE "public"."game_hands" ENABLE ROW LEVEL SECURITY; - -ALTER TABLE "public"."games" ENABLE ROW LEVEL SECURITY; - -ALTER TABLE "public"."profiles" ENABLE ROW LEVEL SECURITY; - -ALTER TABLE "public"."rooms" ENABLE ROW LEVEL SECURITY; - -ALTER PUBLICATION "supabase_realtime" OWNER TO "postgres"; - -GRANT USAGE ON SCHEMA "public" TO "postgres"; -GRANT USAGE ON SCHEMA "public" TO "anon"; -GRANT USAGE ON SCHEMA "public" TO "authenticated"; -GRANT USAGE ON SCHEMA "public" TO "service_role"; - -GRANT ALL ON TABLE "public"."game_districts" TO "anon"; -GRANT ALL ON TABLE "public"."game_districts" TO "authenticated"; -GRANT ALL ON TABLE "public"."game_districts" TO "service_role"; - -GRANT ALL ON TABLE "public"."game_hands" TO "anon"; -GRANT ALL ON TABLE "public"."game_hands" TO "authenticated"; -GRANT ALL ON TABLE "public"."game_hands" TO "service_role"; - -GRANT ALL ON TABLE "public"."games" TO "anon"; -GRANT ALL ON TABLE "public"."games" TO "authenticated"; -GRANT ALL ON TABLE "public"."games" TO "service_role"; - -GRANT ALL ON SEQUENCE "public"."games_id_seq" TO "anon"; -GRANT ALL ON SEQUENCE "public"."games_id_seq" TO "authenticated"; -GRANT ALL ON SEQUENCE "public"."games_id_seq" TO "service_role"; - -GRANT ALL ON TABLE "public"."profiles" TO "anon"; -GRANT ALL ON TABLE "public"."profiles" TO "authenticated"; -GRANT ALL ON TABLE "public"."profiles" TO "service_role"; - -GRANT ALL ON TABLE "public"."rooms" TO "anon"; -GRANT ALL ON TABLE "public"."rooms" TO "authenticated"; -GRANT ALL ON TABLE "public"."rooms" TO "service_role"; - -ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "postgres"; -ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "anon"; -ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "authenticated"; -ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON SEQUENCES TO "service_role"; - -ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "postgres"; -ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "anon"; -ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "authenticated"; -ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON FUNCTIONS TO "service_role"; - -ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "postgres"; -ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "anon"; -ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "authenticated"; -ALTER DEFAULT PRIVILEGES FOR ROLE "postgres" IN SCHEMA "public" GRANT ALL ON TABLES TO "service_role"; - -RESET ALL; - --- --- Dumped schema changes for auth and storage --- - diff --git a/supabase/seed.sql b/supabase/seed.sql deleted file mode 100644 index 8b137891..00000000 --- a/supabase/seed.sql +++ /dev/null @@ -1 +0,0 @@ - diff --git a/upload-assets.js b/upload-assets.js deleted file mode 100644 index e2a10ee2..00000000 --- a/upload-assets.js +++ /dev/null @@ -1,63 +0,0 @@ -import { createClient } from "@supabase/supabase-js"; -import fs from "node:fs"; -import path from "node:path"; -import process from "node:process"; - -// Create a single supabase client for interacting with your database -const url = "https://ryvsflpspddwwacxrnst.supabase.co"; - -const supabase = createClient(url, process.env.PROD_SUPABASE_SERVICE_ROLE_KEY); - -await supabase.storage - .createBucket("assets", { - public: true, - }); - -// refresh styles -await supabase.storage - .from("assets") - .remove(["styles/index.css"]) - -uploadDir("public"); - -function uploadDir(dir) { - for (const entry of fs.readdirSync(dir, { withFileTypes: true })) { - if (entry.isDirectory()) { - uploadDir(path.join(dir, entry.name)); - } else { - let filePath = path.join(entry.parentPath, entry.name); - let contents = fs.readFileSync(filePath); - supabase.storage - .from("assets") - .upload(filePath.substring(7), contents, { - contentType: mimeType(filePath), - }); - } - } -} - -function mimeType(fileName) { - const ext = path.extname(fileName); - switch (ext) { - case ".txt": - return "text/plain;charset=UTF-8"; - case ".css": - return "text/css;charset=UTF-8"; - case ".mp3": - return "audio/mpeg"; - case ".wav": - return "audio/wav"; - case ".png": - return "image/x-png"; - case ".jpeg": - return "image/jpeg"; - case ".jpg": - return "image/jpeg"; - case ".pdf": - return "application/pdf"; - case ".js": - return "application/javascript"; - default: - throw new Error(`Unexpected file ext: ${ext}`); - } -}