-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Use IDENTITY column for int primary keys instead of BIGSERIAL (#…
…293) `BIGSERIAL` is not recommended. See: https://wiki.postgresql.org/wiki/Don%27t_Do_This#Don.27t_use_serial. The recommendation is instead to use `IDENTITY` columns. This PR updates the create `user` table migration (just the one using bigint as the primary key) to create the pk as an IDENTITY column instead of a BIGSERIAL. This PR also adds the `pk_bigint_identity` method to enable creating an IDENTITY pk in any table. The `pk_bigint_identity_options` method is added as well, which is the same except it allows configuring the sequence for the identity generation. See: https://www.postgresql.org/docs/current/sql-createsequence.html Closes #290
- Loading branch information
1 parent
b9fcac4
commit f0d8726
Showing
9 changed files
with
141 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
src/migration/snapshots/roadster__migration__schema__tests__pk_bigint@pk_bigint.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
source: src/migration/schema.rs | ||
expression: table_stmt.to_string(PostgresQueryBuilder) | ||
--- | ||
CREATE TABLE "foo" ( "bar" bigint NOT NULL PRIMARY KEY ) |
5 changes: 5 additions & 0 deletions
5
.../snapshots/roadster__migration__schema__tests__pk_bigint_identity@pk_bigint_identity.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
source: src/migration/schema.rs | ||
expression: table_stmt.to_string(PostgresQueryBuilder) | ||
--- | ||
CREATE TABLE "foo" ( "bar" bigint NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY ) |
5 changes: 5 additions & 0 deletions
5
...tion/snapshots/roadster__migration__schema__tests__pk_bigint_identity_options@case_1.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
source: src/migration/schema.rs | ||
expression: table_stmt.to_string(PostgresQueryBuilder) | ||
--- | ||
CREATE TABLE "foo" ( "bar" bigint NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH 1 INCREMENT BY 1) ) |
5 changes: 5 additions & 0 deletions
5
...tion/snapshots/roadster__migration__schema__tests__pk_bigint_identity_options@case_2.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
source: src/migration/schema.rs | ||
expression: table_stmt.to_string(PostgresQueryBuilder) | ||
--- | ||
CREATE TABLE "foo" ( "bar" bigint NOT NULL PRIMARY KEY GENERATED AS IDENTITY (START WITH 1 INCREMENT BY 1) ) |
5 changes: 5 additions & 0 deletions
5
...tion/snapshots/roadster__migration__schema__tests__pk_bigint_identity_options@case_3.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
source: src/migration/schema.rs | ||
expression: table_stmt.to_string(PostgresQueryBuilder) | ||
--- | ||
CREATE TABLE "foo" ( "bar" bigint NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH -100 INCREMENT BY 1) ) |
5 changes: 5 additions & 0 deletions
5
...tion/snapshots/roadster__migration__schema__tests__pk_bigint_identity_options@case_4.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
source: src/migration/schema.rs | ||
expression: table_stmt.to_string(PostgresQueryBuilder) | ||
--- | ||
CREATE TABLE "foo" ( "bar" bigint NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY (START WITH 0 INCREMENT BY 1) ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
...apshots/roadster__migration__user__create_and_drop_table__tests__create_table_int_pk.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
--- | ||
source: src/migration/user/create_table.rs | ||
source: src/migration/user/create_and_drop_table.rs | ||
expression: query.to_string(PostgresQueryBuilder) | ||
--- | ||
CREATE TABLE IF NOT EXISTS "user" ( "created_at" timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated_at" timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, "id" bigserial NOT NULL PRIMARY KEY, "name" varchar NOT NULL CHECK (CHAR_LENGTH("name") > 0), "username" varchar NOT NULL UNIQUE CHECK (CHAR_LENGTH("username") > 0), "email" varchar NOT NULL UNIQUE CHECK (CHAR_LENGTH("email") > 0), "password" varchar NOT NULL ) | ||
CREATE TABLE IF NOT EXISTS "user" ( "created_at" timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, "updated_at" timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, "id" bigint NOT NULL PRIMARY KEY GENERATED ALWAYS AS IDENTITY, "name" varchar NOT NULL CHECK (CHAR_LENGTH("name") > 0), "username" varchar NOT NULL UNIQUE CHECK (CHAR_LENGTH("username") > 0), "email" varchar NOT NULL UNIQUE CHECK (CHAR_LENGTH("email") > 0), "password" varchar NOT NULL ) |