Skip to content

Commit

Permalink
Cascade
Browse files Browse the repository at this point in the history
  • Loading branch information
pontusab committed Dec 30, 2024
1 parent 528bf18 commit 4502513
Show file tree
Hide file tree
Showing 5 changed files with 315 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/production-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
workingDirectory: "apps/api"
wranglerVersion: "latest"
command: d1 migrations apply languine-production --env production
command: d1 migrations apply languine-production --env production --remote
- name: 🚀 Deploy Project Artifacts to Cloudflare
uses: cloudflare/wrangler-action@v3
with:
Expand Down
29 changes: 29 additions & 0 deletions apps/api/drizzle/0002_hesitant_amazoness.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
PRAGMA foreign_keys=OFF;--> statement-breakpoint
CREATE TABLE `__new_projects` (
`id` text PRIMARY KEY NOT NULL,
`team_id` text NOT NULL,
`name` text NOT NULL,
`description` text,
`created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
FOREIGN KEY (`team_id`) REFERENCES `teams`(`id`) ON UPDATE no action ON DELETE cascade
);
--> statement-breakpoint
INSERT INTO `__new_projects`("id", "team_id", "name", "description", "created_at", "updated_at") SELECT "id", "team_id", "name", "description", "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 TABLE `__new_team_members` (
`id` text PRIMARY KEY NOT NULL,
`team_id` text NOT NULL,
`user_id` text NOT NULL,
`role` text NOT NULL,
`created_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
`updated_at` text DEFAULT CURRENT_TIMESTAMP NOT NULL,
FOREIGN KEY (`team_id`) REFERENCES `teams`(`id`) ON UPDATE no action ON DELETE cascade,
FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
INSERT INTO `__new_team_members`("id", "team_id", "user_id", "role", "created_at", "updated_at") SELECT "id", "team_id", "user_id", "role", "created_at", "updated_at" FROM `team_members`;--> statement-breakpoint
DROP TABLE `team_members`;--> statement-breakpoint
ALTER TABLE `__new_team_members` RENAME TO `team_members`;
276 changes: 276 additions & 0 deletions apps/api/drizzle/meta/0002_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,276 @@
{
"version": "6",
"dialect": "sqlite",
"id": "c1e50742-3003-4e1c-82e0-237e3e6c2876",
"prevId": "358d4d4a-8540-4b87-b0d4-478cbea7c2fc",
"tables": {
"projects": {
"name": "projects",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"team_id": {
"name": "team_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
}
},
"indexes": {},
"foreignKeys": {
"projects_team_id_teams_id_fk": {
"name": "projects_team_id_teams_id_fk",
"tableFrom": "projects",
"tableTo": "teams",
"columnsFrom": [
"team_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"team_members": {
"name": "team_members",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"team_id": {
"name": "team_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"user_id": {
"name": "user_id",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"role": {
"name": "role",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
}
},
"indexes": {},
"foreignKeys": {
"team_members_team_id_teams_id_fk": {
"name": "team_members_team_id_teams_id_fk",
"tableFrom": "team_members",
"tableTo": "teams",
"columnsFrom": [
"team_id"
],
"columnsTo": [
"id"
],
"onDelete": "cascade",
"onUpdate": "no action"
},
"team_members_user_id_users_id_fk": {
"name": "team_members_user_id_users_id_fk",
"tableFrom": "team_members",
"tableTo": "users",
"columnsFrom": [
"user_id"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"teams": {
"name": "teams",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"users": {
"name": "users",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"avatar": {
"name": "avatar",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"provider": {
"name": "provider",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"created_at": {
"name": "created_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
},
"updated_at": {
"name": "updated_at",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "CURRENT_TIMESTAMP"
}
},
"indexes": {
"users_email_unique": {
"name": "users_email_unique",
"columns": [
"email"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
}
},
"views": {},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}
7 changes: 7 additions & 0 deletions apps/api/drizzle/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
"when": 1735563592170,
"tag": "0001_warm_pepper_potts",
"breakpoints": true
},
{
"idx": 2,
"version": "6",
"when": 1735563924272,
"tag": "0002_hesitant_amazoness",
"breakpoints": true
}
]
}
4 changes: 2 additions & 2 deletions apps/api/src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const teamMembers = sqliteTable("team_members", {
id: text("id").primaryKey(),
teamId: text("team_id")
.notNull()
.references(() => teams.id),
.references(() => teams.id, { onDelete: "cascade" }),
userId: text("user_id")
.notNull()
.references(() => users.id),
Expand All @@ -35,7 +35,7 @@ export const projects = sqliteTable("projects", {
id: text("id").primaryKey(),
teamId: text("team_id")
.notNull()
.references(() => teams.id),
.references(() => teams.id, { onDelete: "cascade" }),
name: text("name").notNull(),
description: text("description"),
createdAt: text("created_at").notNull().default(sql`CURRENT_TIMESTAMP`),
Expand Down

0 comments on commit 4502513

Please sign in to comment.