I am using a nodejs backend with sequelize.
Right now when I make a model like
import { sequelize } from "../db/sequelize.mjs";
import { DataTypes } from "sequelize";
const User = sequelize.define(
"User",
{
username: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
email: {
type: DataTypes.STRING,
allowNull: false,
unique: true,
},
},
{
tableName: "users", // Specify the actual table name
}
);
export { User };
the id comes through like 1
or 2
but I want sequelize to default all models to use uuid
instead of typing that in each model I want to type that as the default value in the sequelize config here
import { Sequelize } from "sequelize";
// the config for the sequelize connection to the psql db
const sequelize = new Sequelize({
dialect: "postgres",
username: "user",
host: "postgresql",
database: "mydatabase",
password: "password",
port: 5432,
define: {
timestamps: true,
// by default sequelize is camelcase (i.e. 'createdAt') and psql cant handle camelcase
// we want to default all db names to use underscores as well (i.e. 'created_at')
underscored: true,
},
});
export { sequelize };
I am struggling to find documentation on this