I use codeship for build my app with following config file. everything is fine before I use one controller to retrieve data from a view "virtual table". From my local, the code is fine. but during codeship build process, error report that Table 'test.testview' doesn't exist. any way I can use sails-mysql adapter to create the virtal table in codeship build process?
module.exports.connections = {
codeshipDb: {
adapter: 'sails-mysql',
host: '127.0.0.1',
user: 'root',
password: 'test',
database: 'test'
},
}
Related
Trying to deploy Strapi on Heroku with Postgres as described here
https://strapi.io/documentation/v3.x/deployment/heroku.html
But I get this error
error: no pg_hba.conf entry for host "84.212.51.43", user "ssqqeaz***", database "d6gtu***", SSL off
I use Heroku Postgres add-on.
My database config:
module.exports = ({ env }) => ({
defaultConnection: 'default',
connections: {
default: {
connector: 'bookshelf',
settings: {
client: 'postgres',
host: env('DATABASE_HOST', '127.0.0.1'),
port: env.int('DATABASE_PORT', 27017),
database: env('DATABASE_NAME', 'strapi'),
username: env('DATABASE_USERNAME', ''),
password: env('DATABASE_PASSWORD', ''),
},
options: {
ssl: true
},
},
},
});
Why? Please help!
try to change ssl : true into ssl : false
The current configuration you've posted will not work with a Heroku Postgres database. The primary concern here is that you're reading components of your postgres database url out of manually set config vars. This is very much recommended against by Heroku because they may need to move the database to a new host in the case of disasters. DATABASE_URL is set by Heroku when you create a database on an app and it's the one config var you can rely on to stay up-to-date. Moving on...
You will need to parse the username, password, host, port and database name out of the DATABASE_URL config var and supply those to the attributes of the settings block. Based on the error you provided, I can tell you're not presently doing this because Heroku databse usernames all start with a 'u', so something is very wrong if you get the error user "ssqqeaz***". As a first step you might try hard coding these values in the settings block to make sure it works (make sure to rotate the credentials after you do it, or otherwise clean up your git history to prevent leaked creds). The pattern for a postgres connection url is something like this: postgres:// $USERNAME : $PASSWORD # $HOSTNAME : $PORT / $DATABASE_NAME.
Not sure if it will help moving your config around...
remove ssl from option Key
insert ssl after password inside of settings Key
eg.
ssl: env.bool('DATABASE_SSL', false),
also check your app config vars inside of Heroku and make sure you have the required postgres config vars setup and they match the heroku generated DATABASE_URL config var.
lastly check your ./config/server.js file and make sure your host is 0.0.0.0
eg.
module.exports = ({ env }) => ({
host: env('HOST', '0.0.0.0'),
port: env.int('PORT', 1337),
admin: {
auth: {
secret: env('ADMIN_JWT_SECRET', '**********************************'),
},
},
});
In knex documentation of configuration of knexfile.js for PostgreSQL, they have a property called client, which looks this way:
...
client: 'pg'
...
However, going through some other projects that utilize PostgreSQL I noticed that they have a different value there, which looks this way:
...
client: 'postgresql'
...
Does this string correspond to the name of some sort of command line tool that is being used with the project or I misunderstand something?
Postgresql is based on a server-client model as described in 'Architectural Fundamentals'
psql is the standard cli client of postgres as mentioned here in the docs.
A client may as well be a GUI such as pg-admin, or a node-package such as 'pg' - here's a list.
The client parameter is required and determines which client adapter will be used with the library.
You should also read the docs of 'Server Setup and Operation'
To initialize the library you can do the following (in this case on localhost):
var knex = require('knex')({
client: 'mysql',
connection: {
host : '127.0.0.1',
user : 'your_database_user',
password : 'your_database_password',
database : 'myapp_test'
}
})
The standard user of the client deamon ist 'postgres' - which you can use of course, but its highly advisable to create a new user as stated in the docs and/or apply a password to the standard user 'postgres'.
On Debian stretch i.E.:
# su - postgres
$ psql -d template1 -c "ALTER USER postgres WITH PASSWORD 'SecretPasswordHere';"
Make sure you delete the command line history so nobody can read out your pwd:
rm ~/.psql_history
Now you can add a new user (i.E. foobar) on the system and for postgres
# adduser foobar
and
# su - postgres
$ createuser --pwprompt --interactive foobar
Lets look at the following setup:
module.exports = {
development: {
client: 'xyz',
connection: { user: 'foobar', database: 'my_app' }
},
production: { client: 'abc', connection: process.env.DATABASE_URL }
};
This basically tells us the following:
In dev - use the client xyz to connect to postgresqls database my_app with the user foobar (in this case without pwd)
In prod - retrieve the globalenv the url of the db-server is set to and connect via the client abc
Here's an example how node's pg-client package opens a connection pool:
const pool = new Pool({
user: 'foobar',
host: 'someUrl',
database: 'someDataBaseName',
password: 'somePWD',
port: 5432,
})
If you could clarify or elaborate your setup or what you like to achieve a little more i could give you some more detailed info - but i hope that helped anyways..
I want to create basic crud through sails framework. I had run these command
sails new sails_app
sails generate api employee
connection.js
module.exports.connections = {
mysql: {
adapter: 'sails-mysql',
host: 'localhost',
user: 'root',
password: 'MyTestPassword123',
database: 'employeehandbook'
}
}
I hit this url
http://localhost:1337/employee/create?name=Brij&email=test#techbrij.com&phone=123-456-7890
OutPut:
{
"name": "Brij",
"email": "test#techbrij.com",
"phone": "123-456-7890",
"createdAt": "2016-02-24T11:23:32.841Z",
"updatedAt": "2016-02-24T11:23:32.841Z",
"id": 1
}
Now I checked the database, There is no one table created by sails
Is this create table automatically or will I create it?
or how to run migrations in sails?
You should place your connection at
config/env/development.js
like that:
models: {
connection: 'mysql'
},
Tables are created automatically in Sails. This is how you do it:
In config/models.js set migrate:create
In config/env/development.js set connection:'mysql' (since that's what you named your connection in config/connections.js
THEN to create/update tables run sails lift which will start your app in development mode, allowing tables to be created. At that point, check if the table has been created (it should exist).
I had issues correctly configuring my couchbase adapter in sails-js. I am using the sails-cbes adapter. The documentation fails to mention the key to use. For any who might struggle as I did, below is my configuration file:
{
...
//couchbase
cb: {
adapter: 'sails-cbes',
host: 'localhost',
port: 8091,
user: 'user',
pass: 'password',
bucket: {
name: 'bucket',
pass: 'bucketPassword'
}
}
},
...
Assuming that by 'key' you refer to the 'password' fields:
The first password is the one you set up in the dialogue the first time you log in to https://localhost:8091.
The bucket is not being created automatically so you would have to do that manually in couchbase. Then you have the option to set a password for the bucket itself, but the default is just empty string. Elasticsearch indexing is automated as long as you declare the mapping in the model.
The configuration file should be in sails-project/config/connections.js and it should look something like this:
sailsCbes: {
adapter: 'sails-cbes',
cb: { ... },
es: { ... }
}
You can try it out by creating a model within sails that uses this connection.
As for the dependencies, you need to install couchbase and elasticsearch yourself, then from the sails-cbes folder do a sudo npm install and you should be good to go. For test dependencies, run npm install inside the test folder.
Hope this helps
I think you don't understand how sailsjs adapter works.
Please spend some time and read the documentation of sailsjs, specially the connections configuration (adapters)
http://sailsjs.org/#!/documentation/reference/sails.config/sails.config.connections.html
What is the correct way to set a db connection in Sails v.0.10.x for production use? I expected Sails to use the connection I referred to in production.js when I start my app in production mode (environment), but it doesn't. It seems to always always use the default connection - 'localDiskDb'.
However, when I start sails in development mode (environment), it does use the connection specified in config/development.js, as I would have expected.
UPDATED
Note: I was mistaken when I wrote the location of production.js. It was in /config/env/production.js just like sgress454 said it should be. Actually, this file was created by the generator and put in the right place and I didn't change that.
config/env/production.js looks like this:
// config/env/production.js
module.exports = {
connection: 'mongo_production'
};
config/models.js looks like this:
// config/models.js
module.exports.models = {
// connection: 'localDiskDb'
};
config/connections.js looks like this:
// config/connections.js
module.exports.connections = {
mongo_development: {
adapter: 'sails-mongo',
host: 'localhost',
port: 27017,
user: '',
password: '',
database: 'my_local_db'
},
mongo_production: {
adapter: 'sails-mongo',
url: 'mongodb://me:mypw#foobar.mongohq.com:10052/my_production_db'
}
};
Couple of issues here:
Per-environment configuration files need to go in the config/env subdirectory, or else they'll be treated the same as regular config files (i.e., not given precedence). If you have multiple files trying to set the same key, results will be unpredictable.
You're attempting to change the default connection for models by setting the connection config key; it needs to be models.connection.
Putting the two together, you need a config/env/production.js file that looks like this:
module.exports = {
models: {
connection: 'mongo_production'
}
};
Then when lifting in production mode, models will use the mongo_production connection by default.
In sails version 0.12 there will be two env files under config/env folder.
So we can write mode specific (production/development) configuration in those two files.
In order to run our sails app in specific mode, we must follow the below steps:
Step 1)
In config/local.js file
module.exports = {
// port: process.env.PORT || 1337, // comment this line if you want to set the different ports for different modes
environment: process.env.NODE_ENV || 'development'
};
Step 2) In env/developement.js file
Write the development specific configurations.
module.exports = {
port: 8080, // will change from default port 1337 to 8080
models: {
connection: 'developement_db',
migrate: 'alter'
}
};
Step 3) In env/production.js file
Write the production specific configurations.
module.exports = {
port: 9090, // will change from default port 1337 to 9090
models: {
connection: 'production_db',
migrate: 'safe'
}
};
Step 4) To run sails app in specific mode,
To run in production mode
$ NODE_ENV=production npm start
Sails will be running on port 9090
To run in developement mode
$ NODE_ENV=developement npm start
Sails will be running on port 8080