While out of the box Sequelize will seem a bit opinionated it's trivial to both legacy and forward proof your application by defining (otherwise generated) table and field names.
While out of the box Sequelize will seem a bit opinionated it's trivial to both legacy and forward proof your application by defining (otherwise generated) table and field names.
## Tables
## Tables
```js
sequelize.define('User',{
},{
tableName:'users'
});
```
## Fields
## Fields
sequelize.define('ModelName', {
userId: {
type: Sequelize.INTEGER,
field: 'user_id'
}
});
```
## Primary keys
Sequelize will assume your table has a `id` primary key property by default.
To define your own primary key:
```js
sequelize.define('collection', {
uid: {
type: Sequelize.INTEGER,
primaryKey: true,
autoIncrement: true // Automatically gets converted to SERIAL for postgres
}
});
sequelize.define('collection', {
uuid: {
type: Sequelize.UUID,
primaryKey: true
}
});
```
And if your model has no primary key at all you can use `Model.removeAttribute('id');`
`sequelize.sync()` will, based on your model definitions, create any missing tables. If `force: true` it will first drop tables before recreating them.
`sequelize.sync()` will, based on your model definitions, create any missing tables.
If `force: true` it will first drop tables before recreating them.
## Migrations / Manual schema changes
## Migrations / Manual schema changes
Sequelize has a [sister library](https://github.com/sequelize/umzug) for handling execution and logging of migration tasks.
Sequelize has a [sister library](https://github.com/sequelize/umzug) for handling execution and logging of migration tasks.
Sequelize provides a list of ways to programmaticaly create or change a table schema.
Sequelize provides a list of ways to programmaticaly create or change a table schema.