Commit Graph

42 Commits

Author SHA1 Message Date
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
fabianlindfors
a04f94ff97 Add Postgres connection options to CLI 2021-11-11 20:36:37 +01:00
fabianlindfors
a407a2d809 Run backfills in batches
Previously a simple UPDATE query was used to backfill the table. This
causes excessive locking and is inefficient on large tables. Now we
instead run backfills in batches of a thousand rows. The batches are
determined based on primary key and iterated in ascending order.
2021-11-09 00:53:24 +01:00
fabianlindfors
e27be94619 Add primary key to schema
We need to know the primary key to perform efficient batch updates.
2021-11-08 23:49:49 +01:00
fabianlindfors
78d8aabd5b Enable composite primary keys when creating table
Also makes the primary key a mandatory field. We'll need primary keys in
order to perform efficient batch updates later.
2021-11-08 23:32:14 +01:00
fabianlindfors
40d16c3367 Move new migrations to InProgress status
Previously the new migrations were directly added to the migrations
lists. Now they are instead added to a vector in the InProgress status
and moved to the migrations list once the migration is complete.

Another status should be added later to indicate that a migration is
currently being applied. Right now, if a migration fails and then the
migrations are changed before being retried, there could be some
dangling changes.
2021-11-08 00:09:30 +01:00
fabianlindfors
23034f2198 Add new migration for creating indices 2021-10-27 00:55:29 +02:00
fabianlindfors
0762a5025a Add missing headings to README 2021-10-27 00:19:29 +02:00
fabianlindfors
03a4180409 Update README with working TOC 2021-10-27 00:15:54 +02:00
fabianlindfors
c27afadbd2 Add foreign keys option to create table migration 2021-10-27 00:10:02 +02:00
fabianlindfors
10699fa46c Add primary key option to create table migration 2021-10-26 23:00:18 +02:00
fabianlindfors
acf7c15448 Add command to abort migration 2021-10-26 00:32:37 +02:00
fabianlindfors
7d8302a0a4 Initial commit 2021-10-26 00:31:09 +02:00