Commit Graph

79 Commits

Author SHA1 Message Date
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