goofysystem
goofysystem
Explore posts from servers
DTDrizzle Team
Created by goofysystem on 7/28/2024 in #help
Getting SQLITE Constraint error with `foreign_keys off`
All I'm doing is dropping default fields from the tables. I had recently learned about PRAGMA foreign_key=off thing and had previously been manually moving over children tables every migration 💀 . But this non-cursed way seems to not work as expected as I'm running into foreign key constraint check. Any help would be greatly appreciated. Below is the generated sql file and I'm using Turso.
PRAGMA foreign_keys=off;
--> statement-breakpoint

ALTER TABLE team_member RENAME TO team_member_old;--> statement-breakpoint
ALTER TABLE tournament RENAME TO tournament_old;--> statement-breakpoint

CREATE TABLE `team_member` (
`id` text PRIMARY KEY NOT NULL,
`team_id` text NOT NULL,
`position` text NOT NULL,
`invite_status` text NOT NULL,
`user_id` text NOT NULL,
FOREIGN KEY (`team_id`) REFERENCES `team`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`user_id`) REFERENCES `dancer`(`user_id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint

INSERT INTO team_member (id, team_id, position, invite_status, user_id)
SELECT id, team_id, position, invite_status, user_id
FROM team_member_old;
--> statement-breakpoint

CREATE TABLE `tournament` (
`id` text PRIMARY KEY NOT NULL,
`version` text NOT NULL,
`battle_id` text NOT NULL,
`status` text NOT NULL,
`created_at` text DEFAULT (strftime('%s', 'now')),
`updated_at` text DEFAULT (strftime('%s', 'now'))
);
--> statement-breakpoint

INSERT INTO tournament (id, version, battle_id, status, created_at, updated_at)
SELECT id, version, battle_id, status, created_at, updated_at
FROM tournament_old;
--> statement-breakpoint

DROP TABLE team_member_old;--> statement-breakpoint
DROP TABLE tournament_old;--> statement-breakpoint

PRAGMA foreign_key_check;--> statement-breakpoint

PRAGMA foreign_keys=on;
PRAGMA foreign_keys=off;
--> statement-breakpoint

ALTER TABLE team_member RENAME TO team_member_old;--> statement-breakpoint
ALTER TABLE tournament RENAME TO tournament_old;--> statement-breakpoint

CREATE TABLE `team_member` (
`id` text PRIMARY KEY NOT NULL,
`team_id` text NOT NULL,
`position` text NOT NULL,
`invite_status` text NOT NULL,
`user_id` text NOT NULL,
FOREIGN KEY (`team_id`) REFERENCES `team`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`user_id`) REFERENCES `dancer`(`user_id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint

INSERT INTO team_member (id, team_id, position, invite_status, user_id)
SELECT id, team_id, position, invite_status, user_id
FROM team_member_old;
--> statement-breakpoint

CREATE TABLE `tournament` (
`id` text PRIMARY KEY NOT NULL,
`version` text NOT NULL,
`battle_id` text NOT NULL,
`status` text NOT NULL,
`created_at` text DEFAULT (strftime('%s', 'now')),
`updated_at` text DEFAULT (strftime('%s', 'now'))
);
--> statement-breakpoint

INSERT INTO tournament (id, version, battle_id, status, created_at, updated_at)
SELECT id, version, battle_id, status, created_at, updated_at
FROM tournament_old;
--> statement-breakpoint

DROP TABLE team_member_old;--> statement-breakpoint
DROP TABLE tournament_old;--> statement-breakpoint

PRAGMA foreign_key_check;--> statement-breakpoint

PRAGMA foreign_keys=on;
2 replies
CDCloudflare Developers
Created by goofysystem on 3/17/2024 in #pages-help
Typesense search breaks the app when refreshing the page.
No description
2 replies
DTDrizzle Team
Created by goofysystem on 3/5/2024 in #help
Error performing migration: LibsqlError: SQLITE_UNKNOWN: SQLite error: cannot rollback
I've already tried downgrading to drizzle kit v0.19 as advised in https://discord.com/channels/933071162680958986/933071163184283651/1204583958679912488 Migration works locally with sqld instance but fails when run against the remote turso database.
Error performing migration: LibsqlError: SQLITE_UNKNOWN: SQLite error: cannot rollback - no transaction is active
at mapHranaError (file:///home/runner/work/utc/utc/node_modules/.pnpm/@libsql+client@0.3.1/node_modules/@libsql/client/lib-esm/hrana.js:286:16)
at file:///home/runner/work/utc/utc/node_modules/.pnpm/@libsql+client@0.3.1/node_modules/@libsql/client/lib-esm/hrana.js:170:37
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async HttpTransaction.rollback (file:///home/runner/work/utc/utc/node_modules/.pnpm/@libsql+client@0.3.1/node_modules/@libsql/client/lib-esm/hrana.js:172:13)
at LibSQLSession.transaction (/home/runner/work/utc/utc/node_modules/.pnpm/drizzle-orm@0.29.2_@cloudflare+workers-types@4.20231010.0_@libsql+client@0.3.1_@types+react@1_3cr644gqxuhfs2c75frekmndw4/node_modules/src/libsql/session.ts:90:4)
at SQLiteAsyncDialect.migrate (/home/runner/work/utc/utc/node_modules/.pnpm/drizzle-orm@0.29.2_@cloudflare+workers-types@4.20231010.0_@libsql+client@0.3.1_@types+react@1_3cr644gqxuhfs2c75frekmndw4/node_modules/src/sqlite-core/dialect.ts:772:3)
at main (/home/runner/work/utc/utc/infra/db/tournament/src/migrate.ts:14:9) {
code: 'SQLITE_UNKNOWN',
[cause]: [ResponseError: SQLite error: cannot rollback - no transaction is active] {
code: 'SQLITE_UNKNOWN',
proto: {
message: 'SQLite error: cannot rollback - no transaction is active',
code: 'SQLITE_UNKNOWN'
}
}
}
 ELIFECYCLE  Command failed with exit code 1.
error: Recipe `migrate` failed on line 19 with exit code 1
Error performing migration: LibsqlError: SQLITE_UNKNOWN: SQLite error: cannot rollback - no transaction is active
at mapHranaError (file:///home/runner/work/utc/utc/node_modules/.pnpm/@libsql+client@0.3.1/node_modules/@libsql/client/lib-esm/hrana.js:286:16)
at file:///home/runner/work/utc/utc/node_modules/.pnpm/@libsql+client@0.3.1/node_modules/@libsql/client/lib-esm/hrana.js:170:37
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async HttpTransaction.rollback (file:///home/runner/work/utc/utc/node_modules/.pnpm/@libsql+client@0.3.1/node_modules/@libsql/client/lib-esm/hrana.js:172:13)
at LibSQLSession.transaction (/home/runner/work/utc/utc/node_modules/.pnpm/drizzle-orm@0.29.2_@cloudflare+workers-types@4.20231010.0_@libsql+client@0.3.1_@types+react@1_3cr644gqxuhfs2c75frekmndw4/node_modules/src/libsql/session.ts:90:4)
at SQLiteAsyncDialect.migrate (/home/runner/work/utc/utc/node_modules/.pnpm/drizzle-orm@0.29.2_@cloudflare+workers-types@4.20231010.0_@libsql+client@0.3.1_@types+react@1_3cr644gqxuhfs2c75frekmndw4/node_modules/src/sqlite-core/dialect.ts:772:3)
at main (/home/runner/work/utc/utc/infra/db/tournament/src/migrate.ts:14:9) {
code: 'SQLITE_UNKNOWN',
[cause]: [ResponseError: SQLite error: cannot rollback - no transaction is active] {
code: 'SQLITE_UNKNOWN',
proto: {
message: 'SQLite error: cannot rollback - no transaction is active',
code: 'SQLITE_UNKNOWN'
}
}
}
 ELIFECYCLE  Command failed with exit code 1.
error: Recipe `migrate` failed on line 19 with exit code 1
1 replies
DTDrizzle Team
Created by goofysystem on 1/13/2024 in #help
How to fetch with multiple ids
const ticketListingRows = await orderDb
.select()
.from(ticketListing)
.where(sql`id IN (3,4) AND event_id = ${eventId}`);
const ticketListingRows = await orderDb
.select()
.from(ticketListing)
.where(sql`id IN (3,4) AND event_id = ${eventId}`);
This query gives me:
RangeError: Only finite numbers (not Infinity or NaN) can be passed as arguments
RangeError: Only finite numbers (not Infinity or NaN) can be passed as arguments
Hows everyone fetching with multiple ids?
8 replies
CDCloudflare Developers
Created by goofysystem on 10/12/2023 in #pages-help
Sveltekit + Lucia: Error: The script will never generate a response.
No description
2 replies
CDCloudflare Developers
Created by goofysystem on 9/13/2023 in #workers-help
403 Error using Turso in local development when running wrangler dev with `--remote` flag
LibsqlError: SERVER_ERROR: Server returned HTTP status 403
at mapHranaError (index.js:12991:12)
at HttpClient2.execute (index.js:13296:13)
at async PreparedQuery.all (index.js:13476:18)
at async index.js:14053:26
at async index.js:2793:5
at async index.js:2695:7
at async index.js:2022:62
at async jsonError (index.js:14078:12) {
code: SERVER_ERROR,
name: LibsqlError,
stack: LibsqlError: SERVER_ERROR: Server returned HTTP st…022:62
at async jsonError (index.js:14078:12),
message: SERVER_ERROR: Server returned HTTP status 403,
cause: HttpServerError: Server returned HTTP status 403
at errorFromResponse (index.js:12380:10)
a…
}
LibsqlError: SERVER_ERROR: Server returned HTTP status 403
at mapHranaError (index.js:12991:12)
at HttpClient2.execute (index.js:13296:13)
at async PreparedQuery.all (index.js:13476:18)
at async index.js:14053:26
at async index.js:2793:5
at async index.js:2695:7
at async index.js:2022:62
at async jsonError (index.js:14078:12) {
code: SERVER_ERROR,
name: LibsqlError,
stack: LibsqlError: SERVER_ERROR: Server returned HTTP st…022:62
at async jsonError (index.js:14078:12),
message: SERVER_ERROR: Server returned HTTP status 403,
cause: HttpServerError: Server returned HTTP status 403
at errorFromResponse (index.js:12380:10)
a…
}
You only get this error when running wrangler dev with --remote flag.
wrangler dev src/index.ts #works
wrangler dev src/index.ts --remote #gets libsql 403 error
wrangler dev src/index.ts #works
wrangler dev src/index.ts --remote #gets libsql 403 error
Here's a repo that demonstrates this: https://github.com/zestsystem/cloudflare-worker-turso/tree/main
3 replies
CDCloudflare Developers
Created by goofysystem on 8/24/2023 in #pages-help
@sveltejs/adapter-cloudflare problem in a monorepo
I have a local workspace package that I import into my sveltekit project. Lets say this package has kysely and @libsql/kysely as its dependencies. Consuming this package results in a build failure like this:
Could not resolve "node:stream"
.svelte-kit/output/server/entries/pages/(auth)/onboarding/_page.server.js:14:19:
14 │ import stream from "node:stream";
╵ ~~~~~~~~~~~~~
The package "node:stream" wasn't found on the file system but is built into node. Are you trying
to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

Could not resolve "node:stream"
.svelte-kit/output/server/entries/pages/(auth)/onboarding/_page.server.js:14:19:
14 │ import stream from "node:stream";
╵ ~~~~~~~~~~~~~
The package "node:stream" wasn't found on the file system but is built into node. Are you trying
to bundle for node? You can use "platform: 'node'" to do that, which will remove this error.

Now if I pnpm install the dependencies of the workspace package directly to the sveltekit project, so in this case kysely and @libsql/kysely, the build is successful. This means that whenever sveltekit consumes a package, I would need to make sure that sveltekit has its dependencies explicitly installed as well. I have confirmed this with a package that uses @aws-sdk as well. Build fails when @aws-sdk is not directly installed to sveltekit, works when it is installed.
3 replies