不要怂,就是干,撸起袖子干!

Commit 35be8e00 by Evan Committed by Sushant

feat(postgres): support autoIncrementIdentity (#11235)

1 parent ff93d7c4
......@@ -494,8 +494,12 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
}
if (attribute.autoIncrement) {
if (attribute.autoIncrementIdentity) {
sql += ' GENERATED BY DEFAULT AS IDENTITY';
} else {
sql += ' SERIAL';
}
}
if (Utils.defaultValueSchemable(attribute.defaultValue)) {
sql += ` DEFAULT ${this.escape(attribute.defaultValue, attribute)}`;
......
......@@ -875,6 +875,7 @@ class Model {
* @param {boolean} [attributes.column.primaryKey=false] If true, this attribute will be marked as primary key
* @param {string} [attributes.column.field=null] If set, sequelize will map the attribute name to a different name in the database
* @param {boolean} [attributes.column.autoIncrement=false] If true, this column will be set to auto increment
* @param {boolean} [attributes.column.autoIncrementIdentity=false] If true, combined with autoIncrement=true, will use Postgres `GENERATED BY DEFAULT AS IDENTITY` instead of `SERIAL`. Postgres 10+ only.
* @param {string} [attributes.column.comment=null] Comment for this column
* @param {string|Model} [attributes.column.references=null] An object with reference configurations
* @param {string|Model} [attributes.column.references.model] If this column references another table, provide it here as a Model, or a string
......
......@@ -113,6 +113,10 @@ if (dialect.startsWith('postgres')) {
expectation: { id: 'INTEGER SERIAL PRIMARY KEY' }
},
{
arguments: [{ id: { type: 'INTEGER', primaryKey: true, autoIncrement: true, autoIncrementIdentity: true } }],
expectation: { id: 'INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY' }
},
{
arguments: [{ id: { type: 'INTEGER', defaultValue: 0 } }],
expectation: { id: 'INTEGER DEFAULT 0' }
},
......
......@@ -1270,6 +1270,11 @@ export interface ModelAttributeColumnOptions extends ColumnOptions {
autoIncrement?: boolean;
/**
* If this field is a Postgres auto increment field, use Postgres `GENERATED BY DEFAULT AS IDENTITY` instead of `SERIAL`. Postgres 10+ only.
*/
autoIncrementIdentity?: boolean;
/**
* Comment for the database
*/
comment?: string;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!