sequelizer generated postgres tables cannot be accessed - node.js

I'm having problems creating models with sequelizer. Or more accurately I can create models and migrate them, but I cannot access, modify or delete them via psql.
I'm creating the model like this:
sequelize model:generate --name Device --attributes pid:string
output:
Sequelize CLI [Node: 4.6.1, CLI: 3.0.0, ORM: 4.22.6]
WARNING: This version of Sequelize CLI is not fully compatible with
Sequelize v4. https://github.com/sequelize/cli#sequelize-support
New model was created at
/home/matti/workspace/db_demo/server/models/device.js . New migration
was created at
/home/matti/workspace/db_demo/server/migrations/20171114134820-Device.js
.
migrating like this:
$ sequelize db:migrate
Sequelize CLI [Node: 4.6.1, CLI: 3.0.0, ORM: 4.22.6]
WARNING: This version of Sequelize CLI is not fully compatible with
Sequelize v4. https://github.com/sequelize/cli#sequelize-support
Loaded configuration file "server/config/config.json". Using
environment "development". sequelize deprecated String based operators
are now deprecated. Please use Symbol based operators for better
security, read more at
http://docs.sequelizejs.com/manual/tutorial/querying.html#operators
node_modules/sequelize/lib/sequelize.js:236:13
== 20171114134820-create-device: migrating =======
== 20171114134820-create-device: migrated (0.044s)
after this I can see the tables in psql:
device-dev=# \d
List of relations
Schema | Name | Type | Owner
--------+----------------+----------+-------
public | Devices | table | matti
public | Devices_id_seq | sequence | matti
public | SequelizeMeta | table | matti
However I cannot list the table:
device-dev=# \d Devices
Did not find any relation named "Devices".
my user credentials (using it as matti):
List of roles
Role name | Attributes | Member of
-----------+------------------------------------------------------------+-----------
matti | Superuser, Create DB | {}
postgres | Superuser, Create role, Create DB, Replication, Bypass RLS | {}
used versions:
Sequelize:
Sequelize CLI [Node: 4.6.1, CLI: 3.0.0, ORM: 4.22.6]
postgres:
psql (PostgreSQL) 10.1
nodejs:
v4.6.1
npm:
2.15.9
I'm working in Ubuntu 16.04.
I've reverted the migration and dropped the db just to be certain. But it didn't have any effect. Nor did restarting the postgres.
I can create, list and delete the db:ses as user "matti" from psql. But not the ones generated by the sequelizer.

Related

Mysql to postgres Migration pgloader not working - No data imported No Errors

I tried the following command and it returns no errors but the data is not imported in my postgres database.
Database is already created in Postgres.
pgloader mysql://user:password#127.0.0.1/db_name postgresql://pgloader_pg:password#127.0.0.1/pg_db_name
This is the result:
LOG pgloader version "3.6.7~devel"
I am not sure what is the issue.

sequelize does not create database on local machine

I am running:
sequelize db:migrate
on my local machine and it outputs:
Sequelize CLI [Node: 15.10.0, CLI: 6.2.0, ORM: 5.8.6]
Loaded configuration file "src/db/db.config.js".
Using environment "development".
but no migration takes place on my local machine. The same code and command migrate the DB normally on a Google cloud instance. How do I debug this problem? My device is Macbook Pro running macOs High Sierra 10.13.6.
Note: the database is already created. Even when I try to delete the DB and run sequelize db:create, still nothing happens.

commiting new changes to migrate command - sequelize-cli Nodejs

I have trouble with sequelize-cli in nodejs. suppose we define a new model with this command :
sequelize model:create --name User --attributes username:string,password:string,email:string,role:string,mobile:string
as you know this command make a migration file in migrations directory.
and with this command I can migrate my model to the database :
sequelize db:migrate
so this is ok . but what about my new changes in my model? how can I commit my new changes to database ?I need a proper way for that.
in django framework there were two basic commands :
makemigrations => for detecting new changes
migrate => for commiting to database
Just use migration:create CLI command (https://github.com/sequelize/cli) to generate new migration file and edit this file manually to make the changes you need.

Not able to connect postgresql with odoo

I configured odoo in aws ec2 and connecting Postgresql from rds when I run the command ./odoo-bin --config=/etc/odoo.conf and try to access from a browser, I'm getting the following error:
ERROR odoo_db odoo.modules.loading: Database odoo_db not initialized, you can force it with `-i base`
File "/opt/odoo/odoo/odoo/modules/registry.py", line 176, in __getitem__
return self.models[model_name]
KeyError: 'ir.http' - - -
and also I'm getting this error as well:
STATEMENT: SELECT latest_version FROM ir_module_module WHERE name='base'
ERROR odoo_db odoo.sql_db: bad query: SELECT latest_version FROM ir_module_module WHERE name='base'
ERROR: relation "ir_module_module" does not exist
In command line run:
./odoo-bin --addons-path=addons --database=odoo --db_user=odoo --db_password=odoo --db_host=localhost --db_port=5432 -i INIT
explicitly give db name, user and password, "-i INIT" option initialises the odoo database
The first glance issue is though the DB has created in Postgres but it has not the required odoo related setup records i.e. base setup. You can verify by directly accessing the DB and see the number of tables or browsing some tables.
It happens sometimes that you create the DB [specifically giving similar DB names as you have already created before and deleted later [its dropped from PG but still has traces in session or DB location path], it will not get initialized properly.
Solution:
Create sample DB with different name initial 4 characters different completely and check
Initialize the DB from odoo.conf file add db_name = < Your DB Name > {for experiment purpose put completely different name} and restart odoo services and check
Hope it will help. Njoy troubleshooting!
First do what #FaisalAnsari says in here (what I reference below):
*
Go to RDS and create a database in PostgreSQL and configure the
server.conf file as the given below.
;This is the password that allows database operations:
;admin_passwd = admin
db_host = rds_endpoint (after creating database you will get
rds_endpoint)
db_port = False
db_user = "user name which is created by you to the database"
db_password = "password which is created"
;addons_path =
/home/deadpool/workspace/odoo_13_community/custom_addons,
/home/deadpool/workspace/odoo_13_community/custom_addons
Then go to the command line and do the following.
Stop your odoo instance
~$ service odoo stop
Enable command line for the user odoo
~$ chsh -s /bin/bash odoo
execute odoo from command line as user odoo
~$ runuser -l odoo -c "odoo -i base -d YourRDSDatabase --db_host YourAmazonRDSHost.Address.rds.amazonaws.com -r YourRDSDatabaseUserName -w YourRDSDatabasePassword --stop-after-init"
After the initialization finished, start odoo service
~$ service odoo start
Troubleshooting :
if odoo doesn't start correctly make sure that the database user in your RDS instance have privileges at least on the database you are using.
~$ psql --host=YourAmazonRDSHost.Address.rds.amazonaws.com --port=5432 --username=YourRDSDatabaseUserName --password --dbname=YourRDSDatabase
and when you are inside postgresql type the following:
~$ grant all privileges on database YourRDSDatabase to YourRDSDatabaseUserName;
~$ \q
and try again from step 3.
Hope that Helps!!

How to run sql script for Postgres in Docker?

I am following this post to run SQL script to create default table.
Here is my docker compose file
version: "3"
services:
  web:
    build: .
    volumes:
      - ./:/usr/src/app/
      - /usr/src/app/node_modules
    ports:
      - “3000:3000”
    depends_on:
      - postgres
  postgres:
    container_name: postgres
    build:
      context: .
      dockerfile: pgDockerfile
    environment:
      POSTGRES_PASSWORD: test
      POSTGRES_USER: test
    ports:
      - 5432:5432
Here is my pgDockerfile
FROM postgres:9.6-alpine
# copy init sql
ADD 00-initial.sql /docker-entrypoint-initdb.d/
Here is my sql script
CREATE EXTENSION IF NOT EXISTS "uuid-ossp";
CREATE TABLE IF NOT EXISTS test (
    id text NOT NULL,
    title varchar(200) NOT NULL
);
I can build and run docker-compose up, and I see the following message:
postgres | CREATE DATABASE
postgres |
postgres | CREATE ROLE
postgres |
postgres |
postgres | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/00-initial-data.sql
postgres | CREATE EXTENSION
postgres | CREATE TABLE
postgres |
postgres |
postgres | LOG: received fast shutdown request
postgres | LOG: aborting any active transactions
postgres | waiting for server to shut down....LOG: autovacuum launcher shutting down
postgres | LOG: shutting down
postgres | LOG: database system is shut down
postgres | done
postgres | server stopped
postgres |
postgres | PostgreSQL init process complete; ready for start up.
postgres |
postgres | LOG: database system was shut down at 2017-03-22 21:36:16 UTC
postgres | LOG: MultiXact member wraparound protections are now enabled
postgres | LOG: database system is ready to accept connections
postgres | LOG: autovacuum launcher started
It seems like the db is shut down after the table is created. I think that’s the standard process for Postgres Docker but when I login to Postgres, I don’t see my table that is supposed to be there.
I login through
docker exec -it $(my postgres container id) sh
#su - postgres
#psql
# \d => No relations found.
I am not sure if this is the right way to create default data for Postgres.
I think that your docker works as intended, but it's not quite doing what you think. When setting POSTGRES_USER, but not POSTGRES_DB, the system will default to using the user name as database name, so your table is in the test database!
Using \l to list your databases will show the databases, and then you can use \c test to connect to the database. Once connected, \d will list your relations!

Resources