Commit Graph

62 Commits

Author SHA1 Message Date
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
fabianlindfors
68cb024ac7 Add automatic Docker image publishing
When a Github release is created, the Docker image will be built and
published to Docker Hub.
2021-12-28 16:45:37 +01:00
fabianlindfors
db36ba0c1b Add Dockerfile 2021-12-28 16:44:52 +01:00
fabianlindfors
fda6dc8f40 Add support for generated constraints on columns 2021-12-28 16:01:11 +01:00
fabianlindfors
101a414e00 Improve README 2021-12-28 15:58:48 +01:00
fabianlindfors
1a28a4ffdf Update installation instructions in README 2021-12-28 15:25:30 +01:00
fabianlindfors
b44145b568 Update clap and add derive feature flag 2021-12-27 14:11:43 +01:00
fabianlindfors
9f23ed38c1 Remove explicit schema tracking
Before, we explicitly tracked the current schema and relied on that in
our migrations. This makes things more complicated as we need to keep
track of not just tables and columns but also primary keys, constraints
etc.

This commit remove the schema tracking and instead queries the
database for the current schema. During migrations, we temporarily store
the changes that are made, for example having temporary columns override
real ones and combine these with the current schema in the database.
This is handled in schema.rs.

These changes also broke our previously handling of triggers and
functions and how we detected if an insert/update was made against the
old or new schema during a migration. The previous method, using a
temporary __reshape_is_new column has been replaced with some helper
functions which inspect the search_path setting and uses that to
determine which schema is being used. During migrations, we can also set
the custom "reshape.is_old_schema" setting to force the old schema, for
example during batch updates.

This greatly simplifies the triggers as we can now simply call a helper
function in Postgres, `reshape.is_old_schema()`, to determine which
schema the modification was made for.
2021-12-27 12:40:57 +01:00
fabianlindfors
fa269ee692 Remove dependency on schema module for batch updates
This is a first, small step in removing schema tracking entirely.
Instead we should probe the dabatase directly for the current schema.
This makes it easier to start using Reshape on an existing database
without having to specify the entire schema first.
2021-12-03 22:49:11 +01:00
fabianlindfors
cbb1834080 Add rename table action 2021-11-17 23:39:03 +01:00
fabianlindfors
d529a48637 Document remove_table action 2021-11-17 23:07:12 +01:00
fabianlindfors
7c18d56d82 Add remove table action 2021-11-17 23:01:49 +01:00
fabianlindfors
3cb74a535e Fix issue where column couldn't be altered multiple times
Previously, having multiple alter_column actions for a single column
could cause issues as the triggers and batch updates referenced the
wrong columns.

This commit also simplifies the batch update procedure. Rather than
running the actual update on existing rows, a NOP update will be
run which in turn will trigger the triggers to update the new temporary
columns.
2021-11-15 00:11:19 +01:00
fabianlindfors
94c0aefe50 Fix missing up and down for alter_column action
The alter_column was always using UPPER and LOWER rather than the passed
up and down settings. This commit also adjusts the column names for
temporary columns as multiple alter_columns actions would conflict if
they edited the same column. They still conflict in other places which
will be fixed later.
2021-11-14 14:00:17 +01:00
fabianlindfors
f5049324c2 Document remove_column action 2021-11-11 23:31:17 +01:00
fabianlindfors
49aed1a4f4 Add migration context for each migration action
The context stores the index of the current migration and action. This
index is used to provide ordering of triggers as well as providing
unique names for things like temporary columns and procedures. The
Context struct exposes a prefix() function which returns a unique string
which can be used as a prefix to triggers, columns, procedures etc.
2021-11-11 23:22:20 +01:00
fabianlindfors
b728f0c642 Add flag for directories to look for migrations in 2021-11-11 21:43:44 +01:00
fabianlindfors
86f77f497c Add generate-schema-query command 2021-11-11 20:47:07 +01:00