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

Commit 35be8e00 by Evan Committed by Sushant

feat(postgres): support autoIncrementIdentity (#11235)

1 parent ff93d7c4
...@@ -494,7 +494,11 @@ class PostgresQueryGenerator extends AbstractQueryGenerator { ...@@ -494,7 +494,11 @@ class PostgresQueryGenerator extends AbstractQueryGenerator {
} }
if (attribute.autoIncrement) { if (attribute.autoIncrement) {
sql += ' SERIAL'; if (attribute.autoIncrementIdentity) {
sql += ' GENERATED BY DEFAULT AS IDENTITY';
} else {
sql += ' SERIAL';
}
} }
if (Utils.defaultValueSchemable(attribute.defaultValue)) { if (Utils.defaultValueSchemable(attribute.defaultValue)) {
......
...@@ -875,6 +875,7 @@ class Model { ...@@ -875,6 +875,7 @@ class Model {
* @param {boolean} [attributes.column.primaryKey=false] If true, this attribute will be marked as primary key * @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 {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.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} [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=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 * @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')) { ...@@ -113,6 +113,10 @@ if (dialect.startsWith('postgres')) {
expectation: { id: 'INTEGER SERIAL PRIMARY KEY' } 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 } }], arguments: [{ id: { type: 'INTEGER', defaultValue: 0 } }],
expectation: { id: 'INTEGER DEFAULT 0' } expectation: { id: 'INTEGER DEFAULT 0' }
}, },
......
...@@ -1270,6 +1270,11 @@ export interface ModelAttributeColumnOptions extends ColumnOptions { ...@@ -1270,6 +1270,11 @@ export interface ModelAttributeColumnOptions extends ColumnOptions {
autoIncrement?: boolean; 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 for the database
*/ */
comment?: string; comment?: string;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!