Skip to content

feat: Use IDENTITY column for int primary keys instead of BIGSERIAL#293

Merged
spencewenski merged 1 commit into
mainfrom
do-not-use-serial
Jul 25, 2024
Merged

feat: Use IDENTITY column for int primary keys instead of BIGSERIAL#293
spencewenski merged 1 commit into
mainfrom
do-not-use-serial

Conversation

@spencewenski
Copy link
Copy Markdown
Member

@spencewenski spencewenski commented Jul 25, 2024

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

`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
@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 25, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 47.72%. Comparing base (b9fcac4) to head (71de444).

Files Coverage Δ
src/migration/schema.rs 100.00% <100.00%> (ø)
src/migration/user/create_and_drop_table.rs 100.00% <100.00%> (ø)

Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b9fcac4...71de444. Read the comment docs.

@spencewenski spencewenski merged commit f0d8726 into main Jul 25, 2024
@spencewenski spencewenski deleted the do-not-use-serial branch July 25, 2024 07:47
@github-actions github-actions Bot mentioned this pull request Jul 25, 2024
spencewenski pushed a commit that referenced this pull request Jul 25, 2024
## 🤖 New release
* `roadster`: 0.5.9 -> 0.5.10

<details><summary><i><b>Changelog</b></i></summary><p>

<blockquote>

##
[0.5.10](roadster-v0.5.9...roadster-v0.5.10)
- 2024-07-25

### Added
- Use IDENTITY column for int primary keys instead of BIGSERIAL
([#293](#293))

### Fixed
- Add "if exists" to user's drop_table migration statement
([#292](#292))

### Other
- Add tests for schema and check helper methods
([#289](#289))
</blockquote>


</p></details>

---
This PR was generated with
[release-plz](https://github.com/MarcoIeni/release-plz/).

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Don’t use serial for id field

1 participant