Skip to content

Commit

Permalink
db: add the triggers back in, patch some issues with drizzle-orm
Browse files Browse the repository at this point in the history
  • Loading branch information
patosullivan committed Jan 13, 2025
1 parent 197354f commit 1411c2a
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
4 changes: 2 additions & 2 deletions apps/tlon-mobile/ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ PODS:
- nanopb/encode (= 2.30910.0)
- nanopb/decode (2.30910.0)
- nanopb/encode (2.30910.0)
- op-sqlite (5.0.5):
- op-sqlite (11.2.4):
- React
- React-callinvoker
- React-Core
Expand Down Expand Up @@ -1816,7 +1816,7 @@ SPEC CHECKSUMS:
libvmaf: 27f523f1e63c694d14d534cd0fddd2fab0ae8711
libwebp: 1786c9f4ff8a279e4dac1e8f385004d5fc253009
nanopb: 438bc412db1928dac798aa6fd75726007be04262
op-sqlite: 12039198fdf455a3af0e18420b656c23cf8ecc01
op-sqlite: f3b4b5ea0baa4a15259875ba126fe3fcf02ee092
PromisesObjC: f5707f49cb48b9636751c5b2e7d227e43fba9f47
PromisesSwift: 9d77319bbe72ebf6d872900551f7eeba9bce2851
RCT-Folly: 7169b2b1c44399c76a47b5deaaba715eeeb476c0
Expand Down
5 changes: 5 additions & 0 deletions packages/app/lib/nativeDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ export class NativeDb extends BaseDb {
}

async runMigrations() {
if (!this.client || !this.connection) {
logger.warn('runMigrations called before setupDb, ignoring');
return;
}

try {
await this.connection?.migrateClient(this.client!);
this.connection?.execute(TRIGGER_SETUP);
Expand Down
43 changes: 39 additions & 4 deletions patches/drizzle-orm@0.36.1.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/op-sqlite/session.cjs b/op-sqlite/session.cjs
index f1ce597e8a6e0e325788cac540a8fde32d36bb42..e6e2e6a65efa6f725d07264cc7c3a2a7040449a0 100644
index f1ce597e8a6e0e325788cac540a8fde32d36bb42..1307b71255df58adc6fc7ed2fc45c9505aa6762e 100644
--- a/op-sqlite/session.cjs
+++ b/op-sqlite/session.cjs
@@ -49,33 +49,30 @@ class OPSQLiteSession extends import_session.SQLiteSession {
Expand Down Expand Up @@ -56,8 +56,12 @@ index f1ce597e8a6e0e325788cac540a8fde32d36bb42..e6e2e6a65efa6f725d07264cc7c3a2a7
}
}
class OPSQLitePreparedQuery extends import_session.SQLitePreparedQuery {
@@ -94,7 +91,14 @@ class OPSQLitePreparedQuery extends import_session.SQLitePreparedQuery {
return this.client.executeAsync(this.query.sql, params);
@@ -91,10 +88,17 @@ class OPSQLitePreparedQuery extends import_session.SQLitePreparedQuery {
run(placeholderValues) {
const params = (0, import_sql.fillPlaceholders)(this.query.params, placeholderValues ?? {});
this.logger.logQuery(this.query.sql, params);
- return this.client.executeAsync(this.query.sql, params);
+ return this.client.execute(this.query.sql, params);
}
async all(placeholderValues) {
- const { fields, joinsNotNullableMap, query, logger, customResultMapper, client } = this;
Expand Down Expand Up @@ -88,6 +92,15 @@ index f1ce597e8a6e0e325788cac540a8fde32d36bb42..e6e2e6a65efa6f725d07264cc7c3a2a7
const params = (0, import_sql.fillPlaceholders)(query.params, placeholderValues ?? {});
logger.logQuery(query.sql, params);
if (!fields && !customResultMapper) {
@@ -127,7 +138,7 @@ class OPSQLitePreparedQuery extends import_session.SQLitePreparedQuery {
values(placeholderValues) {
const params = (0, import_sql.fillPlaceholders)(this.query.params, placeholderValues ?? {});
this.logger.logQuery(this.query.sql, params);
- return this.client.executeRawAsync(this.query.sql, params);
+ return this.client.executeRaw(this.query.sql, params);
}
/** @internal */
isResponseInArrayMode() {
diff --git a/op-sqlite/session.cjs.map b/op-sqlite/session.cjs.map
index 0a873b1dc081a183d3be8f8c0acd65e90067627b..8f94cfe8a95964bfb98f1322069ff5e29f25fcd7 100644
--- a/op-sqlite/session.cjs.map
Expand Down Expand Up @@ -220,7 +233,7 @@ index 07cae6b6cb6c0c1a11d283ae26aad1c1c1d7cd4d..021c904e0b9d22fad58853669c341b51
}
export {};
diff --git a/op-sqlite/session.js b/op-sqlite/session.js
index ff84604e7998182ef78fbffc8d20019aaf76755e..b924059196f0bc7f368bebd920aa0cbca89f65eb 100644
index ff84604e7998182ef78fbffc8d20019aaf76755e..309968bebceffae5e988aa5204c32f320d37b8a7 100644
--- a/op-sqlite/session.js
+++ b/op-sqlite/session.js
@@ -1,6 +1,6 @@
Expand Down Expand Up @@ -865,3 +878,25 @@ index 3a87d63968c3e4b1ae0c4463ae6f2c9d24c57165..cf187f5be0406d31bdd27c19ebccbee0
"./prisma/mysql/driver": {
"import": {
"types": "./prisma/mysql/driver.d.ts",
diff --git a/sqlite-core/dialect.cjs b/sqlite-core/dialect.cjs
index 6f174d8775e31a9b84c917e2ee2f6c1a17faf44f..2a3084125eae627ce75de52b94d69da20dc74f3f 100644
--- a/sqlite-core/dialect.cjs
+++ b/sqlite-core/dialect.cjs
@@ -566,7 +566,7 @@ class SQLiteSyncDialect extends SQLiteDialect {
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
const migrationTableCreate = import_sql2.sql`
CREATE TABLE IF NOT EXISTS ${import_sql2.sql.identifier(migrationsTable)} (
- id SERIAL PRIMARY KEY,
+ id integer PRIMARY KEY AUTOINCREMENT,
hash text NOT NULL,
created_at numeric
)
@@ -601,7 +601,7 @@ class SQLiteAsyncDialect extends SQLiteDialect {
const migrationsTable = config === void 0 ? "__drizzle_migrations" : typeof config === "string" ? "__drizzle_migrations" : config.migrationsTable ?? "__drizzle_migrations";
const migrationTableCreate = import_sql2.sql`
CREATE TABLE IF NOT EXISTS ${import_sql2.sql.identifier(migrationsTable)} (
- id SERIAL PRIMARY KEY,
+ id integer PRIMARY KEY AUTOINCREMENT,
hash text NOT NULL,
created_at numeric
)
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1411c2a

Please sign in to comment.