question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Database fails to open in production

See original GitHub issue

Issue type:

[ ] question [x] bug report [ ] feature request [ ] documentation issue

Database system/driver:

[ ] cordova [ ] mongodb [ ] mssql [ ] mysql / mariadb [ ] oracle [ ] postgres [ ] cockroachdb [ ] sqlite [ ] sqljs [x] react-native [ ] expo

TypeORM version:

[x] latest [ ] @next [ ] 0.x.x (or put your version here)

Steps to reproduce or a small repository showing the problem:

OPEN database fails in production. Database is working as expected in debug mode.

Expected Behavior

Database should open and initialize tables successfully in production and debug modes.

Current Behavior

Database is opening in debug mode and failing in production

Steps to Reproduce (for bugs)

Using typeorm I have created entities in the following form:

import { EntitySchema } from 'typeorm';
import { StorageModel } from '../models/StorageModel';

export default new EntitySchema({
  name: 'Storage',
  target: StorageModel,
  columns: {
    key: { type: 'text', primary: true },
    value: { type: 'text' },
  },
});

Then I am opening database with the following config:

createConnection({
      name: 'db.sqlite',
      type: 'react-native',
      database: 'react-native',
      location: 'default',
      // logging: ['error', 'query', 'schema'],
      synchronize: true,
      entities: [
        Translation,
        User,
        Post,
        Download,
        Asset,
        Option,
        QueuedRequest,
        Storage,
        HelpItem,
      ],
    });

In debug the database opens correctly and I have used it to create many features. It was going very well until I tried building the release apk. I get the following error in adb logcat

08-08 19:04:52.174 19954 20022 I ReactNativeJS: OPEN database: react-native
08-08 19:04:52.340 19954 20032 E SQLiteLog: (1) near ")": syntax error
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: SQLitePlugin.executeSql[Batch]() failed
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: android.database.sqlite.SQLiteException: near ")": syntax error (code 1): , while compiling: CREATE TABLE "temporary_t" ()
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteConnection.nativePrepareStatement(Native Method)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteConnection.acquirePreparedStatement(SQLiteConnection.java:895)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteConnection.prepare(SQLiteConnection.java:506)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteSession.prepare(SQLiteSession.java:726)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:58)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteQuery.<init>(SQLiteQuery.java:37)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteDirectCursorDriver.query(SQLiteDirectCursorDriver.java:44)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteDatabase.rawQueryWithFactory(SQLiteDatabase.java:1428)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at android.database.sqlite.SQLiteDatabase.rawQuery(SQLiteDatabase.java:1367)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at org.pgsqlite.SQLitePlugin.executeSqlStatementQuery(SQLitePlugin.java:805)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at org.pgsqlite.SQLitePlugin.executeSqlBatch(SQLitePlugin.java:712)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at org.pgsqlite.SQLitePlugin.access$100(SQLitePlugin.java:49)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at org.pgsqlite.SQLitePlugin$DBRunner.run(SQLitePlugin.java:927)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
08-08 19:04:52.340 19954 20032 E unknown:SQLitePlugin: 	at java.lang.Thread.run(Thread.java:764)

Context

Using react-native-sqlite-storage with typeorm to build offline support for a react-native app.

Your Environment

  • typeorm: ^0.2.18
  • React Native SQLite Storage Version used: 3.3.10 and also on 3.2.0
  • React Native version used: 0.60.0
  • Operating System and version (simulator or device): LG G6 Android 8.0.0
  • IDE used: Android Studio
  • Link to your project: Private client project SRY

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

13reactions
jbenzshawelcommented, Oct 24, 2019

This issue is due to minification in release mode changing class names and file names. It can be fixed with the following steps:

  1. yarn add metro-minify-terser
  2. Update the metro config to keep class names and file names. Add the following to the metro.config.js transformer:
minifierPath: 'metro-minify-terser',
minifierConfig: {
    ecma: 8,
    keep_classnames: true,
    keep_fnames: true,
    module: true,
    mangle: {
        module: true,
        keep_classnames: true,
        keep_fnames: true,
    },
 },
2reactions
mirceaniscommented, Oct 27, 2021

Is there a way to instruct typeorm to treat migrations properly without the use of class names, like maybe giving it an array of tuples (migration class, timestamp)?

Read more comments on GitHub >

github_iconTop Results From Across the Web

The production database just went down! What do I do?
Configuring database high availability simply means there will be more than one (1) instance of a database server running; once an instance  ......
Read more >
Ways to Tackle An Error in a Production SQL Server Database
Resolve An Error in a Production SQL Server Database · Discover the extent of corruption: · Act contingent upon the size of damage:...
Read more >
The production database just went down! What do I do?
Configuring database high availability simply means there will be more than one (1) instance of a database server running; once an instance fails,...
Read more >
database fails to open and or prostrct repair fails with error 43 ...
The user doesn't have enough privileges to access the database files. The Windows System Error Code 5 means: "Access is denied." This OS...
Read more >
unable to access data in production environment - CodeProject
Well, when you host a particular website, generally a Virtual Directory name also gets added to the URL. ... The reason being, you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found