balderdashy / balderdashy/sails

Help to get migrations to run on Waterline standalone

Open
#7,231 3 comments 0 reactions 0 assignees View on GitHub
does this answer your question? standalone waterline
Dominant language
JavaScript
Stars
22.8k
Forks
1.9k
PR merge metrics
No merged PRs in 30d

Description

**Node version**: _(18.0.0)_
**DB adapter & version** _(sails-postgresql@4.0.0)_:


I kindly require assistance to get migrations to run on waterline standalone version 0.15.0

My config is as follows:

```javascript
module.exports = {
adapters: {
pg: require('sails-postgresql'),
mysql: require('sails-mysql'),
},
datastores: {
default: {
adapter: 'pg',
host: 'localhost',
port: 5432,
user: 'rcp',
password: 'rcp',
database: 'db_service',
isVersion12OrNewer: true,
},
mysql: {
adapter: 'mysql',
host: 'localhost',
port: 3306,
user: 'db',
password: 'db',
database: 'db_service',
},
},
};

```

My models:

```javascript
module.exports = {
identity: 'pet',
datastore: 'default',
primaryKey: 'id',
migrate: 'alter',
attributes: {
id: {
type: 'number',
autoMigrations: { autoIncrement: true },
},
breed: { type: 'string' },
type: { type: 'string' },
name: { type: 'string' },

// Add a reference to User
owner: {
model: 'user',
},
},
};

```

```javascript
module.exports = {
identity: 'user',
datastore: 'default',
primaryKey: 'id',
migrate: 'alter',
attributes: {
id: {
type: 'number',
autoMigrations: { autoIncrement: true },
},
firstName: { type: 'string' },
lastName: { type: 'string' },

// Add a reference to Pets
pets: {
collection: 'pet',
via: 'owner',
},
},
};
```

The bootstrap file:

```javascript
const Waterline = require('waterline');
const config = require('./config');

const userModel = require('./models/user');
const petModel = require('./models/pet');

const userCollection = Waterline.Collection.extend(userModel);
const petCollection = Waterline.Collection.extend(petModel);

const waterline = new Waterline();

waterline.registerModel(userCollection);
waterline.registerModel(petCollection);

waterline.initialize(config, function (err, ontology) {
if (err) {
console.error(err.message);
return;
}

// Tease out fully initialized models.
let User = ontology.collections.user;
let Pet = ontology.collections.pet;

// Since we're using `await`, we'll scope our selves an async IIFE:
(async () => {
// First we create a user
const user = await User.create({
firstName: 'Neil',
lastName: 'Armstrong',
});

// Then we create the pet
const pet = await Pet.create({
breed: 'beagle',
type: 'dog',
name: 'Astro',
owner: user.id,
});

// Then we grab all users and their pets
const users = await User.find().populate('pets');
console.log(users);
})()
.then(() => {
// All done.
})
.catch((err) => {
console.error(err.message);
}); //_∏_
});

```

My package.json:

```json

{
"name": "db-service",
"version": "1.0.0",
"main": "index.js",
"license": "MIT",
"scripts": {
"dev": "nodemon index.js"
},
"dependencies": {
"sails-mysql": "^2.0.0",
"sails-postgresql": "^4.0.0",
"waterline": "^0.15.0"
},
"devDependencies": {
"nodemon": "^2.0.18"
}
}
```

The issue I am facing is that when I run the bootstrap file, I get the error below:
`Unexpected error from database adapter: relation "public.user" does not exist`

Any assistance on this is highly appreciated.

Error Stack:
```bash
OperationalError [AdapterError]: Unexpected error from database adapter: relation "public.user" does not exist
at callback (/Users/.../Downloads/musings/db-service/index.js:20:27)
... 20 lines matching cause stack trace ...
at Connection.emit (node:events:539:35) {
cause: Error [AdapterError]: Unexpected error from database adapter: relation "public.user" does not exist
at callback (/Users/.../Downloads/musings/db-service/index.js:20:27)
at /Users/.../Downloads/musings/db-service/node_modules/waterline/lib/waterline.js:731:14
at /Users/.../Downloads/musings/db-service/node_modules/async/dist/async.js:952:25
at iteratorCallback (/Users/.../Downloads/musings/db-service/node_modules/async/dist/async.js:997:17)
at /Users/.../Downloads/musings/db-service/node_modules/async/dist/async.js:847:20
at /Users/.../Downloads/musings/db-service/node_modules/waterline/lib/waterline/utils/system/validate-datastore-connectivity.js:42:14
at /Users/.../Downloads/musings/db-service/node_modules/machine/lib/private/help-build-machine.js:954:24
at handlerCbs.success (/Users/.../Downloads/musings/db-service/node_modules/machine/lib/private/help-build-machine.js:814:26)
at Object.releaseConnection (/Users/.../Downloads/musings/db-service/node_modules/machinepack-postgresql/machines/release-connection.js:79:18)
at wrapper (/Users/.../Downloads/musings/db-service/node_modules/@sailshq/lodash/lib/index.js:3282:19)
at parley.retry (/Users/.../Downloads/musings/db-service/node_modules/machine/lib/private/help-build-machine.js:1076:19)
at parley (/Users/.../Downloads/musings/db-service/node_modules/parley/lib/parley.js:140:5)
at Object.runFn [as releaseConnection] (/Users/.../Downloads/musings/db-service/node_modules/machine/lib/private/help-build-machine.js:461:23)
at /Users/.../Downloads/musings/db-service/node_modules/waterline/lib/waterline/utils/system/validate-datastore-connectivity.js:35:27
at /Users/.../Downloads/musings/db-service/node_modules/machine/lib/private/help-build-machine.js:954:24
at handlerCbs.success (/Users/.../Downloads/musings/db-service/node_modules/machine/lib/private/help-build-machine.js:814:26)
at PendingItem.cb [as callback] (/Users/.../Downloads/musings/db-service/node_modules/machinepack-postgresql/machines/get-connection.js:87:20)
at BoundPool._acquireClient (/Users/.../Downloads/musings/db-service/node_modules/pg-pool/index.js:298:21)
at /Users/.../Downloads/musings/db-service/node_modules/pg-pool/index.js:270:21
at Connection. (/Users/.../Downloads/musings/db-service/node_modules/pg/lib/client.js:253:7)
at Object.onceWrapper (node:events:642:26)
at Connection.emit (node:events:539:35) {
adapterMethodName: 'create',
modelIdentity: 'user',
raw: error: relation "public.user" does not exist
at Parser.parseErrorMessage (/Users/.../Downloads/musings/db-service/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/Users/.../Downloads/musings/db-service/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/Users/.../Downloads/musings/db-service/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket. (/Users/.../Downloads/musings/db-service/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:527:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
length: 110,
severity: 'ERROR',
code: '42P01',
detail: undefined,
hint: undefined,
position: '13',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_relation.c',
line: '1363',
routine: 'parserOpenTable'
}
},
isOperational: true,
adapterMethodName: 'create',
modelIdentity: 'user',
raw: error: relation "public.user" does not exist
at Parser.parseErrorMessage (/Users/.../Downloads/musings/db-service/node_modules/pg-protocol/dist/parser.js:287:98)
at Parser.handlePacket (/Users/.../Downloads/musings/db-service/node_modules/pg-protocol/dist/parser.js:126:29)
at Parser.parse (/Users/.../Downloads/musings/db-service/node_modules/pg-protocol/dist/parser.js:39:38)
at Socket. (/Users/.../Downloads/musings/db-service/node_modules/pg-protocol/dist/index.js:11:42)
at Socket.emit (node:events:527:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
at TCP.onStreamRead (node:internal/stream_base_commons:190:23) {
length: 110,
severity: 'ERROR',
code: '42P01',
detail: undefined,
hint: undefined,
position: '13',
internalPosition: undefined,
internalQuery: undefined,
where: undefined,
schema: undefined,
table: undefined,
column: undefined,
dataType: undefined,
constraint: undefined,
file: 'parse_relation.c',
line: '1363',
routine: 'parserOpenTable'
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the failure with the bootstrap file, config.js, models/user.js, and models/pet.js, then inspect the Waterline initialization and migration behavior for the PostgreSQL datastore. Done means the standalone setup creates the required relations before User.create runs, without the reported `public.user` error.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js, postgresql
Domain
backend, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.