mirror of
https://github.com/linsa-io/linsa.git
synced 2026-01-12 12:20:23 +01:00
109 lines
5.8 KiB
SQL
109 lines
5.8 KiB
SQL
CREATE TABLE "archives" (
|
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
"user_id" text NOT NULL,
|
|
"title" text NOT NULL,
|
|
"description" text,
|
|
"type" varchar(32) NOT NULL,
|
|
"content_url" text,
|
|
"content_text" text,
|
|
"thumbnail_url" text,
|
|
"file_size_bytes" integer DEFAULT 0,
|
|
"duration_seconds" integer,
|
|
"mime_type" varchar(128),
|
|
"is_public" boolean DEFAULT false NOT NULL,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "storage_usage" (
|
|
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "storage_usage_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
|
"user_id" text NOT NULL,
|
|
"archives_used" integer DEFAULT 0 NOT NULL,
|
|
"archives_limit" integer DEFAULT 10 NOT NULL,
|
|
"storage_bytes_used" integer DEFAULT 0 NOT NULL,
|
|
"storage_bytes_limit" integer DEFAULT 1073741824 NOT NULL,
|
|
"period_start" timestamp with time zone NOT NULL,
|
|
"period_end" timestamp with time zone NOT NULL,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stream_comments" (
|
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
"stream_username" text NOT NULL,
|
|
"user_id" text NOT NULL,
|
|
"content" text NOT NULL,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stream_replays" (
|
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
"stream_id" uuid NOT NULL,
|
|
"user_id" text NOT NULL,
|
|
"title" text DEFAULT 'Stream Replay' NOT NULL,
|
|
"description" text,
|
|
"status" varchar(32) DEFAULT 'processing' NOT NULL,
|
|
"jazz_replay_id" text,
|
|
"playback_url" text,
|
|
"thumbnail_url" text,
|
|
"duration_seconds" integer,
|
|
"started_at" timestamp with time zone,
|
|
"ended_at" timestamp with time zone,
|
|
"is_public" boolean DEFAULT false NOT NULL,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "streams" (
|
|
"id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
|
|
"user_id" text NOT NULL,
|
|
"title" text DEFAULT 'Live Stream' NOT NULL,
|
|
"description" text,
|
|
"is_live" boolean DEFAULT false NOT NULL,
|
|
"viewer_count" integer DEFAULT 0 NOT NULL,
|
|
"stream_key" text NOT NULL,
|
|
"hls_url" text,
|
|
"webrtc_url" text,
|
|
"thumbnail_url" text,
|
|
"started_at" timestamp with time zone,
|
|
"ended_at" timestamp with time zone,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
CONSTRAINT "streams_stream_key_unique" UNIQUE("stream_key")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stripe_customers" (
|
|
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "stripe_customers_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
|
"user_id" text NOT NULL,
|
|
"stripe_customer_id" text NOT NULL,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
CONSTRAINT "stripe_customers_user_id_unique" UNIQUE("user_id"),
|
|
CONSTRAINT "stripe_customers_stripe_customer_id_unique" UNIQUE("stripe_customer_id")
|
|
);
|
|
--> statement-breakpoint
|
|
CREATE TABLE "stripe_subscriptions" (
|
|
"id" integer PRIMARY KEY GENERATED ALWAYS AS IDENTITY (sequence name "stripe_subscriptions_id_seq" INCREMENT BY 1 MINVALUE 1 MAXVALUE 2147483647 START WITH 1 CACHE 1),
|
|
"user_id" text NOT NULL,
|
|
"stripe_subscription_id" text NOT NULL,
|
|
"stripe_customer_id" text NOT NULL,
|
|
"stripe_price_id" text NOT NULL,
|
|
"status" varchar(32) NOT NULL,
|
|
"current_period_start" timestamp with time zone,
|
|
"current_period_end" timestamp with time zone,
|
|
"cancel_at_period_end" boolean DEFAULT false,
|
|
"created_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
"updated_at" timestamp with time zone DEFAULT now() NOT NULL,
|
|
CONSTRAINT "stripe_subscriptions_stripe_subscription_id_unique" UNIQUE("stripe_subscription_id")
|
|
);
|
|
--> statement-breakpoint
|
|
ALTER TABLE "users" ADD COLUMN "username" text;--> statement-breakpoint
|
|
ALTER TABLE "users" ADD COLUMN "tier" varchar(32) DEFAULT 'free' NOT NULL;--> statement-breakpoint
|
|
ALTER TABLE "archives" ADD CONSTRAINT "archives_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "storage_usage" ADD CONSTRAINT "storage_usage_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "stream_comments" ADD CONSTRAINT "stream_comments_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "stream_replays" ADD CONSTRAINT "stream_replays_stream_id_streams_id_fk" FOREIGN KEY ("stream_id") REFERENCES "public"."streams"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "stream_replays" ADD CONSTRAINT "stream_replays_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "streams" ADD CONSTRAINT "streams_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "stripe_customers" ADD CONSTRAINT "stripe_customers_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "stripe_subscriptions" ADD CONSTRAINT "stripe_subscriptions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
|
|
ALTER TABLE "users" ADD CONSTRAINT "users_username_unique" UNIQUE("username"); |