3

The Official Documentation doesn't explains clearly how define schemas for database by themselves. I'm assuming that Sequelize is more related to MySql than Postgres (where schemas are mandatory).

If I've already created some schemas in Postgres, how I could sync them with Sequelize?

2
  • I think you need to recreate the models using sequelize before you can sync. There was a project I saw that generated models from an existing db (SQL Server(?)) but it didn't work very well for me. Commented Sep 19, 2016 at 19:58
  • I can recreate the models (tables) perfectly with Sequelize. My issue are the Postgres Schemas (public, security, audit, whatever...), that I've created in Postgres. These schemas will contain the models (tables), but for themselves I don't know how sync them with Sequelize. Commented Sep 19, 2016 at 20:06

1 Answer 1

4

You can set the model with the schema using model.schema, something like:

var City = sequelize.define('City', {
    id: {
        type: sequelize.Sequelize.INTEGER,
        primaryKey: true,
        autoIncrement: true,
        field: 'id'
    },
    name: {
        type: sequelize.Sequelize.STRING,
        field: 'name'   
    }
  }, {
    timestamps: false,
    tableName: 'cities'
    });
City.schema("public");
Sign up to request clarification or add additional context in comments.

7 Comments

I think you meant City.schema("public")
I figured but JavaScript doesn't know that!
Thank you so much! It is just all want!
And also, this answer is valid to me: stackoverflow.com/a/32025860/6291719
Nice, this is the way
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.