pubkey / rxdb

A fast, local first, reactive Database for JavaScript Applications https://rxdb.info/
https://rxdb.info/
Apache License 2.0
21.51k stars 1.06k forks source link

Trace Error when attempting to use node-websql adapter #3949

Closed Smolations closed 2 years ago

Smolations commented 2 years ago

I have been googling for a couple of hours now and have yet to see a reproduction of my current issue. I'm trying to spin up RxDB with an expressjs process and the simple "add collections" example is not resulting in success. In fact, I'm getting a rather strange error. I am running node v16.17.0 on Windows 10.

my general `db.js` file ```js const path = require('path'); const { createRxDatabase } = require('rxdb'); const { getRxStoragePouch, addPouchPlugin } = require('rxdb/plugins/pouchdb'); const collections = require('./collections'); addPouchPlugin(require('pouchdb-adapter-node-websql')); module.exports = (async () => { const dbPath = path.join(process.env.USER_DATA_PATH, 'firstRxDb'); console.log('dbPath: ', dbPath); // C:\Users\Me\AppData\Roaming\my-app\firstRxDb const db = await createRxDatabase({ name: dbPath, storage: getRxStoragePouch('websql'), // the name of your adapter }); // this is an RxDatabase instance console.log('db: ', typeof db); Object.entries(collections).forEach(([collectionName, schema]) => { // checked and i get e.g.: `{ bots: { schema: { title: '...', type: 'object', ...} } }` db.addCollections({ [collectionName]: { schema } }); // <-- error throws }); return db; })(); ```
the error ``` Trace: Error: You are using a function which must be overwritten by a plugin. You should either prevent the usage of this function or add the plugin via: import { RxDBMigrationPlugin } from 'rxdb/plugins/migration'; addRxPlugin(RxDBMigrationPlugin); at pluginMissing (C:\Users\Me\my-app\node_modules\rxdb\dist\lib\util.js:70:10) at RxCollectionBase.getDataMigrator (C:\Users\Me\my-app\node_modules\rxdb\dist\lib\rx-collection.js:167:35) at RxCollectionBase.migratePromise (C:\Users\Me\my-app\node_modules\rxdb\dist\lib\rx-collection.js:177:17) at C:\Users\Me\my-app\node_modules\rxdb\dist\lib\rx-collection.js:1040:26 at processTicksAndRejections (node:internal/process/task_queues:96:5) at async Promise.all (index 0) at C:\Users\Me\my-app\node_modules\unload\dist\lib\node.js:39:15 at processTicksAndRejections (node:internal/process/task_queues:96:5) ```
my `package.json` It should be noted that the error occurs _outside_ of the electron environment as I'm running `npm run start:server` to test, which eventually `require`s the `db.js` file. ```json { "name": "my-app", "version": "1.0.0", "description": "My App", "main": ".webpack/main", "scripts": { "postinstall": "semantic-ui-css-patch", "start": "electron-forge start", "start:server": "nodemon ./src/server.js", "package": "electron-forge package", "make": "electron-forge make", "publish": "electron-forge publish", }, "license": "MIT", "electron-config-stuffs": "...", "nodemonConfig": {}, "devDependencies": { "@babel/core": "^7.18.10", "@babel/preset-react": "^7.18.6", "@electron-forge/cli": "^6.0.0-beta.65", "@electron-forge/maker-deb": "^6.0.0-beta.65", "@electron-forge/maker-rpm": "^6.0.0-beta.65", "@electron-forge/maker-squirrel": "^6.0.0-beta.65", "@electron-forge/maker-zip": "^6.0.0-beta.65", "@electron-forge/plugin-webpack": "^6.0.0-beta.65", "@semantic-ui-react/css-patch": "^1.1.2", "@vercel/webpack-asset-relocator-loader": "^1.7.3", "axios": "^0.27.2", "babel-loader": "^8.2.5", "css-loader": "^6.7.1", "electron": "20.0.3", "electron-better-ipc": "^2.0.1", "electron-context-menu": "^3.4.0", "electron-debug": "^3.2.0", "electron-squirrel-startup": "^1.0.0", "electron-store": "^8.1.0", "electron-util": "^0.17.2", "lodash": "^4.17.21", "nanoid": "^4.0.0", "node-loader": "^2.0.0", "nodemon": "^2.0.19", "prop-types": "^15.8.1", "react": "^18.2.0", "react-dom": "^18.2.0", "react-router": "^6.3.0", "react-router-dom": "^6.3.0", "sass": "^1.54.4", "sass-loader": "^13.0.2", "semantic-ui-css": "^2.4.1", "semantic-ui-react": "^2.1.3", "style-loader": "^3.3.1" }, "dependencies": { "@apidevtools/swagger-parser": "^10.1.0", "@twurple/api": "^5.2.1", "@twurple/auth": "^5.2.1", "cookie-parser": "~1.4.4", "copy-webpack-plugin": "^11.0.0", "cors": "^2.8.5", "dotenv": "^16.0.1", "ejs": "~2.6.1", "express": "~4.16.1", "http-errors": "~1.6.3", "morgan": "~1.9.1", "pouchdb-adapter-node-websql": "^7.0.0", "rxdb": "^12.7.16", "rxjs": "^7.5.6", "swagger-ui-express": "^4.5.0" } } ```
pubkey commented 2 years ago

Your schema version is not zero, so you need the migration plugin to migrate database state from zero to your schemas version. Please read the issue template before you create an issue.

Smolations commented 2 years ago

Thank you for responding with useful information even though you didn't think I read the template. I read it, I just didn't think my issue fell squarely under any of the options. I changed my collection version to 0 and the issue was resolved.

I will say that I think the error messaging could have been more helpful in diagnosing the problem, which would have prevented all of this. The example "first collection" in the docs mentioned a version of 0 but did not mention that all initial collections must start with a version of 0. In any case, thanks again! 👍

pubkey commented 2 years ago

You can make a PR to improve the error message.