Skip to content

Commit

Permalink
Merge pull request #24 from alanhoskins/fix/boolean-mode
Browse files Browse the repository at this point in the history
fix: try to use boolean mode from drizzle for shadowEnabled
  • Loading branch information
cmgriffing authored Oct 23, 2024
2 parents 823e431 + e70e4f7 commit 468aa22
Show file tree
Hide file tree
Showing 6 changed files with 291 additions and 8 deletions.
9 changes: 9 additions & 0 deletions playgrounds/app/migrations/0002_dizzy_timeslip.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
DROP INDEX IF EXISTS "users_table_email_unique";--> statement-breakpoint
DROP INDEX IF EXISTS "users_table_githubId_unique";--> statement-breakpoint
DROP INDEX IF EXISTS "users_table_githubUsername_unique";--> statement-breakpoint
DROP INDEX IF EXISTS "users_table_githubAvatarUrl_unique";--> statement-breakpoint
ALTER TABLE `snippets_table` ALTER COLUMN "shadowEnabled" TO "shadowEnabled" integer NOT NULL DEFAULT true;--> statement-breakpoint
CREATE UNIQUE INDEX `users_table_email_unique` ON `users_table` (`email`);--> statement-breakpoint
CREATE UNIQUE INDEX `users_table_githubId_unique` ON `users_table` (`githubId`);--> statement-breakpoint
CREATE UNIQUE INDEX `users_table_githubUsername_unique` ON `users_table` (`githubUsername`);--> statement-breakpoint
CREATE UNIQUE INDEX `users_table_githubAvatarUrl_unique` ON `users_table` (`githubAvatarUrl`);
271 changes: 271 additions & 0 deletions playgrounds/app/migrations/meta/0002_snapshot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
{
"version": "6",
"dialect": "sqlite",
"id": "a9edb9c1-c4eb-4710-9ca9-48355da04fac",
"prevId": "a25d9e7c-46fc-4f89-b78f-a5382632f50d",
"tables": {
"snippets_table": {
"name": "snippets_table",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"userId": {
"name": "userId",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"codeLeft": {
"name": "codeLeft",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"codeRight": {
"name": "codeRight",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"updatedAt": {
"name": "updatedAt",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"snippetWidth": {
"name": "snippetWidth",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 450
},
"yPadding": {
"name": "yPadding",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 42
},
"xPadding": {
"name": "xPadding",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 42
},
"shadowEnabled": {
"name": "shadowEnabled",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": true
},
"shadowOffsetY": {
"name": "shadowOffsetY",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 10
},
"shadowBlur": {
"name": "shadowBlur",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 10
},
"shadowColor": {
"name": "shadowColor",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'#000000'"
},
"shadowOpacity": {
"name": "shadowOpacity",
"type": "real",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0.6
},
"bgColor": {
"name": "bgColor",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'#ffffff'"
},
"language": {
"name": "language",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'tsx'"
},
"theme": {
"name": "theme",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": "'nord'"
}
},
"indexes": {},
"foreignKeys": {
"snippets_table_userId_users_table_id_fk": {
"name": "snippets_table_userId_users_table_id_fk",
"tableFrom": "snippets_table",
"tableTo": "users_table",
"columnsFrom": [
"userId"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
},
"users_table": {
"name": "users_table",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"email": {
"name": "email",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"githubId": {
"name": "githubId",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"githubUsername": {
"name": "githubUsername",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"githubAvatarUrl": {
"name": "githubAvatarUrl",
"type": "text",
"primaryKey": false,
"notNull": true,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
},
"updatedAt": {
"name": "updatedAt",
"type": "integer",
"primaryKey": false,
"notNull": true,
"autoincrement": false,
"default": 0
}
},
"indexes": {
"users_table_email_unique": {
"name": "users_table_email_unique",
"columns": [
"email"
],
"isUnique": true
},
"users_table_githubId_unique": {
"name": "users_table_githubId_unique",
"columns": [
"githubId"
],
"isUnique": true
},
"users_table_githubUsername_unique": {
"name": "users_table_githubUsername_unique",
"columns": [
"githubUsername"
],
"isUnique": true
},
"users_table_githubAvatarUrl_unique": {
"name": "users_table_githubAvatarUrl_unique",
"columns": [
"githubAvatarUrl"
],
"isUnique": true
}
},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {},
"checkConstraints": {}
}
},
"views": {},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
},
"internal": {
"indexes": {}
}
}
7 changes: 7 additions & 0 deletions playgrounds/app/migrations/meta/_journal.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
"when": 1729646676735,
"tag": "0001_burly_alice",
"breakpoints": true
},
{
"idx": 2,
"version": "6",
"when": 1729650906143,
"tag": "0002_dizzy_timeslip",
"breakpoints": true
}
]
}
3 changes: 1 addition & 2 deletions playgrounds/app/src/db/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ export const snippetsTable = sqliteTable('snippets_table', {
snippetWidth: int().notNull().default(450),
yPadding: int().notNull().default(42),
xPadding: int().notNull().default(42),
// sqlite doesn't support booleans
shadowEnabled: int().notNull().default(1),
shadowEnabled: int({ mode: 'boolean' }).notNull().default(true),
shadowOffsetY: int().notNull().default(10),
shadowBlur: int().notNull().default(10),
shadowColor: text().notNull().default('#000000'),
Expand Down
2 changes: 1 addition & 1 deletion playgrounds/app/src/routes/api/snippets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export async function POST(event: APIEvent) {
snippetWidth,
yPadding,
xPadding,
shadowEnabled: shadowEnabled ? 1 : 0,
shadowEnabled,
shadowOffsetY,
shadowBlur,
shadowColor,
Expand Down
7 changes: 2 additions & 5 deletions playgrounds/app/src/routes/api/snippets/[snippetId].ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ export async function GET(event: APIEvent) {
}

return new Response(
JSON.stringify({
...snippet,
shadowEnabled: snippet.shadowEnabled === 1,
}),
JSON.stringify(snippet),
{
status: 200,
headers: {
Expand Down Expand Up @@ -115,7 +112,7 @@ export async function PUT(event: APIEvent) {
snippetWidth,
yPadding,
xPadding,
shadowEnabled: shadowEnabled ? 1 : 0,
shadowEnabled,
shadowOffsetY,
shadowBlur,
shadowColor,
Expand Down

0 comments on commit 468aa22

Please sign in to comment.