Commit Graph

79 Commits

Author SHA1 Message Date
fabianlindfors
8e08941007 Let actions complete without transaction
Some migrations can be completed without needing a transaction for
atomicity. We should avoid transactions for DDL as far as possible to
avoid interfering with other queries and holding locks too long. It's
possible that all actions could be completed without a transaction but
I'm not sure of that yet.

Some migrations also won't work with transactions. For example dropping
an index using `DROP INDEX CONCURRENTLY` doesn't work inside a
transation.

Next step is to perform the same change for aborts.
2022-01-12 00:53:15 +01:00
fabianlindfors
8a130490a0 Use one transaction for each action during abort
This is a continuation on the last two commits. We want to keep
transactions as short-lived as possible when performing schema changes.
2022-01-12 00:06:54 +01:00
fabianlindfors
e27b5d2a23 Use one transaction for each action during completion
This builds on the previous commit to make the transactions even more
granular when completing a migration. Keeping the transaction span short
is important to avoid interfering with other queries.
2022-01-11 23:25:55 +01:00
fabianlindfors
c0ec6ca031 Use one transaction for each migration when completing
We previously used one transaction across all the migrations being
completed, which is not ideal from a locking perspective. Preferably we
want to keep the transactions as short-lived as possible to avoid
interfering with other queries. The next step will be to use one
transaction for each action.

To achieve this, we need to introduce a new intermediate state called
`Completing` which tracks which migrations have been completed so far.
2022-01-11 23:17:40 +01:00
fabianlindfors
bd7aab5675 Use CreateTableBuilder for alter_column tests 2022-01-11 22:35:14 +01:00
fabianlindfors
6f4a575c3c Add support for changing default value with alter_column
Changing the default value only affects the new schema, the old schema
will still use the existing default value. This is to make sure a new
default value doesn't break the old application.
2022-01-10 22:45:00 +01:00
fabianlindfors
c76ea1fba6 Add builder for create_table migration
The builder will help simplify the tests and avoid boilerplate updates
when need fields are added to the create_table migration. We might want
to add builders all migrations later.
2022-01-10 21:59:20 +01:00
fabianlindfors
435a40695a Bump crate version to 0.1.1 2022-01-08 16:09:23 +01:00
fabianlindfors
07774e87b6 Fix incorrect create_table examples 2022-01-06 16:54:35 +01:00
fabianlindfors
af2dbcb06e Remove truncation of migrations during abort
The migrations aren't updated so they shouldn't truncated during an
abort either. Also fixes the indexing for contexts during aborts.
2022-01-05 14:42:47 +01:00
fabianlindfors
54d9dd1b44 Fix incorrect type tag for alter_column migration 2022-01-05 14:15:40 +01:00
fabianlindfors
80cea7f94e Fix bad SQL query in abort for remove_column 2022-01-05 14:15:16 +01:00
fabianlindfors
afea8e304a Use IF EXISTS when dropping helpers 2022-01-05 14:13:54 +01:00
fabianlindfors
751c1975d7 Fix invalid example in README 2022-01-05 14:04:40 +01:00
fabianlindfors
27ec085337 Make foreign_keys optionally when creating tables 2022-01-05 14:03:56 +01:00
fabianlindfors
bf75e00c29 Add release badge to README 2022-01-04 16:22:23 +01:00
fabianlindfors
98cd2751ca Add cargo installation to README 2022-01-04 16:14:40 +01:00
fabianlindfors
3c977cb299 Fix incorrect output path in release pipeline
When using the --target flag, Cargo will output binaries to a different
folder: target/{TARGET}/release/reshape.
2022-01-04 15:50:27 +01:00
fabianlindfors
64d05dad46 Add missing target arg to build command 2022-01-04 15:35:09 +01:00
fabianlindfors
bd50686d32 Remove unused bimap dependency 2022-01-04 15:08:12 +01:00
fabianlindfors
6b21f8dc00 Add missing cleanup assertions to tests 2022-01-04 15:06:40 +01:00
fabianlindfors
cc07512f8c Fix clippy warnings 2022-01-03 22:15:53 +01:00
fabianlindfors
9b21ebfb86 Add check for dangling changes at end of tests
This checks for dangling temporary columns, triggers and function which
were used by migrations but should be removed once the migration has
been completed or aborted.
2022-01-03 22:09:16 +01:00
fabianlindfors
1ddfe95bf0 Add backtrace feature to anyhow
Improved backtrace support for errors in Rust is currently in progress:
https://github.com/rust-lang/rust/issues/53487. Adding the feature lets
anyhow add backtraces already which greatly improves readability of
errors in tests.
2022-01-03 22:03:10 +01:00
fabianlindfors
24c3f28b86 Refactor column tracking in Schema
Column tracking refers to how temporary columns for a column are
tracked. This changes the tracking to use a single vector, the first
element is the original column name and subsequent ones are temporary
columns.
2022-01-03 22:01:16 +01:00
fabianlindfors
33682db021 Remove schema param from migration complete function
Migrations shouldn't need to know about any temporary schema changes
as they should already have been applied once the migration is going
to be completed.
2022-01-03 21:56:13 +01:00
fabianlindfors
bffb602e02 Add Postgres compatibility note to README 2022-01-03 13:38:22 +01:00
fabianlindfors
f34e2b88f2 Adjust README 2022-01-03 13:24:55 +01:00
fabianlindfors
da8a5c3c77 Upgrade clap to 3.0.0 2022-01-03 00:05:54 +01:00
fabianlindfors
0bac1245cd Add context to errors 2022-01-03 00:03:23 +01:00
fabianlindfors
6e005144f4 Rename Context to MigrationContext
Context collides with the anyhow::Context trait.
2022-01-02 23:40:34 +01:00
fabianlindfors
ef82acd480 Return anyhow::Result from main function
This should improve the way errors are displayed for end users with a
list of causes.
2022-01-02 23:34:06 +01:00
fabianlindfors
78c0093412 Add intermediate Applying state
This state is set as soon as a migration is started, before any
migrations are run. If a migration unexpectedly fails and doesn't abort
properly (which should happen automatically), the state will be left
dangling in `Applying`. In that case, it's fine for the user to run
migrate again as all migrations are idempotent.
2022-01-02 23:29:39 +01:00
fabianlindfors
0fe6569b8c Automatically abort when a migration fails 2022-01-02 02:14:37 +01:00
fabianlindfors
c65985e5f9 Change update_schema method to not return Result
`update_schema`shouldn't be able to fail. Any failures should be caught
in the `migrate` method.
2022-01-02 01:33:36 +01:00
fabianlindfors
86254abe63 Add metadata to Cargo.toml 2022-01-01 17:35:16 +01:00
fabianlindfors
b17d358ed1 Add license info to README 2022-01-01 17:27:23 +01:00
Fabian Lindfors
0697774253
Add MIT LICENSE file 2022-01-01 17:22:27 +01:00
fabianlindfors
c54190bfc1 Use temporary column for add column migration
Previously the column was added with its final name directly. This could
cause trouble if there was a column with the same name removed during
the same migration.
2021-12-31 17:20:25 +01:00
fabianlindfors
40ba58b313 Refactor Schema module
The previous implementation Schema couldn't handle some sequence of
migrations. For example when a temporary column is introduced for a
column and that column is then renamed. This new implementation keeps
track of all intermediate (temporary) columns to handle this.

This commit also greatly simplifies the API for `Schema`, creating a
single method on `TableChanges` and `ColumnChanges` for each possible
change: renaming, changing the backing column and removing.
2021-12-31 17:11:48 +01:00
fabianlindfors
570cf4a84b Extend alter_column_multiple test 2021-12-29 23:34:14 +01:00
fabianlindfors
84cf3f9d55 Add Apple Silicon, Linux 32-bit and Linux ARM targets 2021-12-29 11:35:26 +01:00
fabianlindfors
e7d384ea68 Fix macOS cross compilation 2021-12-29 10:41:51 +01:00
fabianlindfors
623dce3404 Use Github CLI for release uploads 2021-12-29 01:15:40 +01:00
fabianlindfors
5ede2a6c7b Add macOS cross-compilation to release action 2021-12-29 00:43:30 +01:00
fabianlindfors
eeb20f6ce0 Use prebuilt cargo Github action
This makes no difference right now but will make it easier to add
cross-compilation later as the cargo Github action has built-in support
for `cross`: https://github.com/actions-rs/cargo.
2021-12-29 00:35:03 +01:00
fabianlindfors
7e64cc488d Push latest and version tag to Docker Hub 2021-12-29 00:30:38 +01:00
fabianlindfors
9dfc3d8fc9 Fix incorrect Docker tag 2021-12-28 17:01:04 +01:00
fabianlindfors
b8137ea0e6 Fix docker login command 2021-12-28 16:52:57 +01:00
fabianlindfors
9873b1c21e Fix invalid workflow definition 2021-12-28 16:48:02 +01:00