Skip to content

Commit

Permalink
Feature/permissions (#59)
Browse files Browse the repository at this point in the history
* wip

* wip

* Add KV

* wip

* wip

* wip
  • Loading branch information
pontusab authored Jan 14, 2025
1 parent f4334c5 commit 47d2d7f
Show file tree
Hide file tree
Showing 76 changed files with 17,346 additions and 463 deletions.
5 changes: 4 additions & 1 deletion apps/web/.env-example
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,7 @@ OPEN_PANEL_CLIENT_SECRET=
NEXT_PUBLIC_OPEN_PANEL_CLIENT_ID=
TURSO_DATABASE_URL=
TURSO_AUTH_TOKEN=
RESEND_API_KEY=
RESEND_API_KEY=
UPSTASH_REDIS_REST_URL=
UPSTASH_REDIS_REST_TOKEN=
OPENAI_API_KEY=
17 changes: 17 additions & 0 deletions apps/web/migrations/0002_equal_rockslide.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
CREATE TABLE `translations` (
`id` text PRIMARY KEY NOT NULL,
`project_id` text NOT NULL,
`source_language` text NOT NULL,
`target_language` text NOT NULL,
`source_text` text NOT NULL,
`translated_text` text NOT NULL,
`branch` text,
`commit` text,
`commit_message` text,
`created_at` integer NOT NULL,
`updated_at` integer NOT NULL,
FOREIGN KEY (`project_id`) REFERENCES `projects`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
CREATE INDEX `project_translations_idx` ON `translations` (`project_id`);--> statement-breakpoint
CREATE INDEX `translations_created_at_idx` ON `translations` (`created_at`);
48 changes: 48 additions & 0 deletions apps/web/migrations/0003_small_red_skull.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
DROP INDEX "accounts_user_id_idx";--> statement-breakpoint
DROP INDEX "provider_compound_idx";--> statement-breakpoint
DROP INDEX "org_email_idx";--> statement-breakpoint
DROP INDEX "invitations_expires_at_idx";--> statement-breakpoint
DROP INDEX "org_user_idx";--> statement-breakpoint
DROP INDEX "organizations_slug_unique";--> statement-breakpoint
DROP INDEX "organizations_api_key_unique";--> statement-breakpoint
DROP INDEX "slug_idx";--> statement-breakpoint
DROP INDEX "org_api_key_idx";--> statement-breakpoint
DROP INDEX "project_idx";--> statement-breakpoint
DROP INDEX "org_idx";--> statement-breakpoint
DROP INDEX "slug_org_idx";--> statement-breakpoint
DROP INDEX "sessions_token_unique";--> statement-breakpoint
DROP INDEX "user_id_idx";--> statement-breakpoint
DROP INDEX "token_idx";--> statement-breakpoint
DROP INDEX "expires_at_idx";--> statement-breakpoint
DROP INDEX "project_translations_idx";--> statement-breakpoint
DROP INDEX "translations_created_at_idx";--> statement-breakpoint
DROP INDEX "users_email_unique";--> statement-breakpoint
DROP INDEX "users_api_key_unique";--> statement-breakpoint
DROP INDEX "email_idx";--> statement-breakpoint
DROP INDEX "identifier_idx";--> statement-breakpoint
DROP INDEX "verifications_expires_at_idx";--> statement-breakpoint
ALTER TABLE `organizations` ALTER COLUMN "api_key" TO "api_key" text;--> statement-breakpoint
CREATE INDEX `accounts_user_id_idx` ON `accounts` (`user_id`);--> statement-breakpoint
CREATE INDEX `provider_compound_idx` ON `accounts` (`provider_id`,`account_id`);--> statement-breakpoint
CREATE INDEX `org_email_idx` ON `invitations` (`organization_id`,`email`);--> statement-breakpoint
CREATE INDEX `invitations_expires_at_idx` ON `invitations` (`expires_at`);--> statement-breakpoint
CREATE INDEX `org_user_idx` ON `members` (`organization_id`,`user_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `organizations_slug_unique` ON `organizations` (`slug`);--> statement-breakpoint
CREATE UNIQUE INDEX `organizations_api_key_unique` ON `organizations` (`api_key`);--> statement-breakpoint
CREATE INDEX `slug_idx` ON `organizations` (`slug`);--> statement-breakpoint
CREATE INDEX `org_api_key_idx` ON `organizations` (`api_key`);--> statement-breakpoint
CREATE INDEX `project_idx` ON `project_settings` (`project_id`);--> statement-breakpoint
CREATE INDEX `org_idx` ON `projects` (`organization_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `slug_org_idx` ON `projects` (`slug`,`organization_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `sessions_token_unique` ON `sessions` (`token`);--> statement-breakpoint
CREATE INDEX `user_id_idx` ON `sessions` (`user_id`);--> statement-breakpoint
CREATE INDEX `token_idx` ON `sessions` (`token`);--> statement-breakpoint
CREATE INDEX `expires_at_idx` ON `sessions` (`expires_at`);--> statement-breakpoint
CREATE INDEX `project_translations_idx` ON `translations` (`project_id`);--> statement-breakpoint
CREATE INDEX `translations_created_at_idx` ON `translations` (`created_at`);--> statement-breakpoint
CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`);--> statement-breakpoint
CREATE UNIQUE INDEX `users_api_key_unique` ON `users` (`api_key`);--> statement-breakpoint
CREATE INDEX `email_idx` ON `users` (`email`);--> statement-breakpoint
CREATE INDEX `identifier_idx` ON `verifications` (`identifier`);--> statement-breakpoint
CREATE INDEX `verifications_expires_at_idx` ON `verifications` (`expires_at`);--> statement-breakpoint
ALTER TABLE `users` ALTER COLUMN "api_key" TO "api_key" text;
48 changes: 48 additions & 0 deletions apps/web/migrations/0004_tense_demogoblin.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
DROP INDEX "accounts_user_id_idx";--> statement-breakpoint
DROP INDEX "provider_compound_idx";--> statement-breakpoint
DROP INDEX "org_email_idx";--> statement-breakpoint
DROP INDEX "invitations_expires_at_idx";--> statement-breakpoint
DROP INDEX "org_user_idx";--> statement-breakpoint
DROP INDEX "organizations_slug_unique";--> statement-breakpoint
DROP INDEX "organizations_api_key_unique";--> statement-breakpoint
DROP INDEX "slug_idx";--> statement-breakpoint
DROP INDEX "org_api_key_idx";--> statement-breakpoint
DROP INDEX "project_idx";--> statement-breakpoint
DROP INDEX "org_idx";--> statement-breakpoint
DROP INDEX "slug_org_idx";--> statement-breakpoint
DROP INDEX "sessions_token_unique";--> statement-breakpoint
DROP INDEX "user_id_idx";--> statement-breakpoint
DROP INDEX "token_idx";--> statement-breakpoint
DROP INDEX "expires_at_idx";--> statement-breakpoint
DROP INDEX "project_translations_idx";--> statement-breakpoint
DROP INDEX "translations_created_at_idx";--> statement-breakpoint
DROP INDEX "users_email_unique";--> statement-breakpoint
DROP INDEX "users_api_key_unique";--> statement-breakpoint
DROP INDEX "email_idx";--> statement-breakpoint
DROP INDEX "identifier_idx";--> statement-breakpoint
DROP INDEX "verifications_expires_at_idx";--> statement-breakpoint
ALTER TABLE `organizations` ALTER COLUMN "api_key" TO "api_key" text NOT NULL;--> statement-breakpoint
CREATE INDEX `accounts_user_id_idx` ON `accounts` (`user_id`);--> statement-breakpoint
CREATE INDEX `provider_compound_idx` ON `accounts` (`provider_id`,`account_id`);--> statement-breakpoint
CREATE INDEX `org_email_idx` ON `invitations` (`organization_id`,`email`);--> statement-breakpoint
CREATE INDEX `invitations_expires_at_idx` ON `invitations` (`expires_at`);--> statement-breakpoint
CREATE INDEX `org_user_idx` ON `members` (`organization_id`,`user_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `organizations_slug_unique` ON `organizations` (`slug`);--> statement-breakpoint
CREATE UNIQUE INDEX `organizations_api_key_unique` ON `organizations` (`api_key`);--> statement-breakpoint
CREATE INDEX `slug_idx` ON `organizations` (`slug`);--> statement-breakpoint
CREATE INDEX `org_api_key_idx` ON `organizations` (`api_key`);--> statement-breakpoint
CREATE INDEX `project_idx` ON `project_settings` (`project_id`);--> statement-breakpoint
CREATE INDEX `org_idx` ON `projects` (`organization_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `slug_org_idx` ON `projects` (`slug`,`organization_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `sessions_token_unique` ON `sessions` (`token`);--> statement-breakpoint
CREATE INDEX `user_id_idx` ON `sessions` (`user_id`);--> statement-breakpoint
CREATE INDEX `token_idx` ON `sessions` (`token`);--> statement-breakpoint
CREATE INDEX `expires_at_idx` ON `sessions` (`expires_at`);--> statement-breakpoint
CREATE INDEX `project_translations_idx` ON `translations` (`project_id`);--> statement-breakpoint
CREATE INDEX `translations_created_at_idx` ON `translations` (`created_at`);--> statement-breakpoint
CREATE UNIQUE INDEX `users_email_unique` ON `users` (`email`);--> statement-breakpoint
CREATE UNIQUE INDEX `users_api_key_unique` ON `users` (`api_key`);--> statement-breakpoint
CREATE INDEX `email_idx` ON `users` (`email`);--> statement-breakpoint
CREATE INDEX `identifier_idx` ON `verifications` (`identifier`);--> statement-breakpoint
CREATE INDEX `verifications_expires_at_idx` ON `verifications` (`expires_at`);--> statement-breakpoint
ALTER TABLE `users` ALTER COLUMN "api_key" TO "api_key" text NOT NULL;
1 change: 1 addition & 0 deletions apps/web/migrations/0005_absent_the_leader.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALTER TABLE `translations` ADD `context` text;
2 changes: 2 additions & 0 deletions apps/web/migrations/0006_rare_yellow_claw.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `translations` ADD `user_id` text REFERENCES users(id);--> statement-breakpoint
ALTER TABLE `translations` ADD `source_format` text NOT NULL;
2 changes: 2 additions & 0 deletions apps/web/migrations/0007_free_sphinx.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ALTER TABLE `translations` ADD `translation_key` text NOT NULL;--> statement-breakpoint
CREATE UNIQUE INDEX `unique_translation_idx` ON `translations` (`project_id`,`translation_key`,`target_language`);
6 changes: 6 additions & 0 deletions apps/web/migrations/0008_daily_clint_barton.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE `translations` RENAME COLUMN "project_id" TO "project_slug";--> statement-breakpoint
DROP INDEX `project_translations_idx`;--> statement-breakpoint
DROP INDEX `unique_translation_idx`;--> statement-breakpoint
CREATE INDEX `project_translations_idx` ON `translations` (`project_slug`);--> statement-breakpoint
CREATE UNIQUE INDEX `unique_translation_idx` ON `translations` (`project_slug`,`translation_key`,`target_language`);--> statement-breakpoint
ALTER TABLE `translations` ALTER COLUMN "project_slug" TO "project_slug" text NOT NULL REFERENCES projects(slug) ON DELETE cascade ON UPDATE no action;
18 changes: 18 additions & 0 deletions apps/web/migrations/0009_pale_ezekiel_stane.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
PRAGMA foreign_keys=OFF;--> statement-breakpoint
CREATE TABLE `__new_projects` (
`id` text PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`slug` text PRIMARY KEY NOT NULL,
`description` text,
`organization_id` text NOT NULL,
`created_at` integer NOT NULL,
`updated_at` integer,
FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
INSERT INTO `__new_projects`("id", "name", "slug", "description", "organization_id", "created_at", "updated_at") SELECT "id", "name", "slug", "description", "organization_id", "created_at", "updated_at" FROM `projects`;--> statement-breakpoint
DROP TABLE `projects`;--> statement-breakpoint
ALTER TABLE `__new_projects` RENAME TO `projects`;--> statement-breakpoint
PRAGMA foreign_keys=ON;--> statement-breakpoint
CREATE INDEX `org_idx` ON `projects` (`organization_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `slug_org_idx` ON `projects` (`slug`,`organization_id`);
24 changes: 24 additions & 0 deletions apps/web/migrations/0010_stormy_speed.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ALTER TABLE `translations` RENAME COLUMN "project_slug" TO "project_id";--> statement-breakpoint
DROP INDEX `project_translations_idx`;--> statement-breakpoint
DROP INDEX `unique_translation_idx`;--> statement-breakpoint
CREATE INDEX `project_translations_idx` ON `translations` (`project_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `unique_translation_idx` ON `translations` (`project_id`,`translation_key`,`target_language`);--> statement-breakpoint
ALTER TABLE `translations` ALTER COLUMN "project_id" TO "project_id" text NOT NULL REFERENCES projects(id) ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
PRAGMA foreign_keys=OFF;--> statement-breakpoint
CREATE TABLE `__new_projects` (
`id` text PRIMARY KEY NOT NULL,
`name` text NOT NULL,
`slug` text NOT NULL,
`description` text,
`organization_id` text NOT NULL,
`created_at` integer NOT NULL,
`updated_at` integer,
FOREIGN KEY (`organization_id`) REFERENCES `organizations`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
INSERT INTO `__new_projects`("id", "name", "slug", "description", "organization_id", "created_at", "updated_at") SELECT "id", "name", "slug", "description", "organization_id", "created_at", "updated_at" FROM `projects`;--> statement-breakpoint
DROP TABLE `projects`;--> statement-breakpoint
ALTER TABLE `__new_projects` RENAME TO `projects`;--> statement-breakpoint
PRAGMA foreign_keys=ON;--> statement-breakpoint
CREATE INDEX `org_idx` ON `projects` (`organization_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `slug_org_idx` ON `projects` (`slug`,`organization_id`);
6 changes: 6 additions & 0 deletions apps/web/migrations/0011_dark_loa.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP INDEX `project_translations_idx`;--> statement-breakpoint
DROP INDEX `unique_translation_idx`;--> statement-breakpoint
ALTER TABLE `translations` ADD `project_slug` text NOT NULL REFERENCES projects(slug);--> statement-breakpoint
CREATE INDEX `project_translations_idx` ON `translations` (`project_slug`);--> statement-breakpoint
CREATE UNIQUE INDEX `unique_translation_idx` ON `translations` (`project_slug`,`translation_key`,`target_language`);--> statement-breakpoint
ALTER TABLE `translations` DROP COLUMN `project_id`;
6 changes: 6 additions & 0 deletions apps/web/migrations/0012_yellow_sasquatch.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE `translations` RENAME COLUMN "project_slug" TO "project_id";--> statement-breakpoint
DROP INDEX `project_translations_idx`;--> statement-breakpoint
DROP INDEX `unique_translation_idx`;--> statement-breakpoint
CREATE INDEX `project_translations_idx` ON `translations` (`project_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `unique_translation_idx` ON `translations` (`project_id`,`translation_key`,`target_language`);--> statement-breakpoint
ALTER TABLE `translations` ALTER COLUMN "project_id" TO "project_id" text NOT NULL REFERENCES projects(id) ON DELETE cascade ON UPDATE no action;
6 changes: 6 additions & 0 deletions apps/web/migrations/0013_organic_shocker.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
DROP INDEX `project_translations_idx`;--> statement-breakpoint
DROP INDEX `unique_translation_idx`;--> statement-breakpoint
ALTER TABLE `translations` ADD `project_slug` text NOT NULL REFERENCES projects(slug);--> statement-breakpoint
CREATE INDEX `project_translations_idx` ON `translations` (`project_slug`);--> statement-breakpoint
CREATE UNIQUE INDEX `unique_translation_idx` ON `translations` (`project_slug`,`translation_key`,`target_language`);--> statement-breakpoint
ALTER TABLE `translations` DROP COLUMN `project_id`;
6 changes: 6 additions & 0 deletions apps/web/migrations/0014_equal_fallen_one.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE `translations` RENAME COLUMN "project_slug" TO "project_id";--> statement-breakpoint
DROP INDEX `project_translations_idx`;--> statement-breakpoint
DROP INDEX `unique_translation_idx`;--> statement-breakpoint
CREATE INDEX `project_translations_idx` ON `translations` (`project_id`);--> statement-breakpoint
CREATE UNIQUE INDEX `unique_translation_idx` ON `translations` (`project_id`,`translation_key`,`target_language`);--> statement-breakpoint
ALTER TABLE `translations` ALTER COLUMN "project_id" TO "project_id" text NOT NULL REFERENCES projects(id) ON DELETE cascade ON UPDATE no action;
6 changes: 6 additions & 0 deletions apps/web/migrations/0015_new_tenebrous.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE `translations` ADD `organization_id` text NOT NULL REFERENCES organizations(id);--> statement-breakpoint
CREATE INDEX `org_translations_idx` ON `translations` (`organization_id`);--> statement-breakpoint
CREATE INDEX `source_language_idx` ON `translations` (`source_language`);--> statement-breakpoint
CREATE INDEX `target_language_idx` ON `translations` (`target_language`);--> statement-breakpoint
CREATE INDEX `created_at_idx` ON `project_settings` (`created_at`);--> statement-breakpoint
CREATE INDEX `api_key_idx` ON `users` (`api_key`);
3 changes: 3 additions & 0 deletions apps/web/migrations/0016_fantastic_susan_delgado.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CREATE INDEX `project_slug_idx` ON `projects` (`slug`);--> statement-breakpoint
CREATE INDEX `project_org_id_idx` ON `projects` (`organization_id`);--> statement-breakpoint
CREATE INDEX `translations_project_id_idx` ON `translations` (`project_id`);
Loading

0 comments on commit 47d2d7f

Please sign in to comment.