Commit Graph

34 Commits

Author SHA1 Message Date
fabianlindfors
814620a215 Add new add_foreign_key action 2022-01-21 18:00:41 +01:00
fabianlindfors
4e0e112eb2 Safely remove indices when removing column 2022-01-20 19:31:21 +01:00
fabianlindfors
16f64181f0 Add new remove_enum action 2022-01-19 23:14:43 +01:00
fabianlindfors
953be4d3eb Add new create_enum action 2022-01-19 23:00:45 +01:00
fabianlindfors
1680906e16 Add support for unique and non-B-tree indices in alter_column 2022-01-16 00:36:57 +01:00
fabianlindfors
9cac25299a Refactor tests to use test framework
This has the added benefit of removing the need for builders and the
derive_builder dependency.
2022-01-15 16:15:31 +01:00
fabianlindfors
a7d70f80b8 Use TOML for migrations in test framework
Previously we set up migrations directly as structs which doesn't match
how users will create them. For the new test framework, we'll instead
write TOML for migrations. This brings the tests closer to how an end
user will interact with Reshape and also lets us write tests to match
the examples in the documentation.
2022-01-15 14:47:28 +01:00
fabianlindfors
945e6374d8 Add test framework
This reduces the amount of boilerplate required to run a test and also
has the added benefit of extending tests as we can now easily test both the
completion and abort paths. So far two tests have been ported over,
create_table and add_column, with the rest to follow.

The framework also improves the output of tests, adding sections clearly
indicating in which part of the migration process a test failed.
2022-01-14 23:49:19 +01:00
fabianlindfors
353a5c22b1 Add option to set index type for add_index 2022-01-14 12:34:38 +01:00
fabianlindfors
5691ad261b Use CreateTableBuilder in failure test 2022-01-14 11:58:21 +01:00
fabianlindfors
dd90cac03a Break out Index struct from add_index
This makes the format of `add_index` a bit more consistent with
`add_column` which has a nested definition for the column. This also
sets up for us to allow adding indices in `create_table`.
2022-01-14 11:53:31 +01:00
fabianlindfors
2a3fda7a90 Add option to create unique index with add_index 2022-01-14 11:44:12 +01:00
fabianlindfors
88da0d2364 Use advisory lock to avoid conflicts between instances
This protects all database access using a Postgres advisory lock. This
way we can avoid problems when two instances of Reshape try to change
the same database at the same time.
2022-01-14 11:25:32 +01:00
fabianlindfors
2d04d33b95 Switch State struct into enum
With the old fields in the `State` broken out we can now make `State` a
proper enum, replacing the nested `Status`. The naming with both `State`
and `Status` was a bit confusing.
2022-01-14 00:12:01 +01:00
fabianlindfors
7c48974308 Use separate table for completed migrations
Before, the entire state was stored as a JSON encoded blob including all
completed migrations. This commits moves the migrations into a dedicated
table, which prevents the encoded from growing indefinitely. The size of
the state probably wouldn't have become a problem but it feels weird for
a schema migration tool to not use a proper schema.

Next, the version stored in the state struct will be moved to a separate
key in the `reshape.data` table and `State` will become an enum with the
same structure as `Status`. The naming right now is a bit confusing.
2022-01-13 23:46:07 +01:00
fabianlindfors
86b649d14a Copy indices to temporary columns for alter_column
Until now, using alter_column would cause indices to be lost as they
weren't copied to the temporary column. This fixes that for indices that
consist of one or more actual columns. It won't work for indices on
expressions.
2022-01-13 18:19:54 +01:00
fabianlindfors
480bcf8af1 Add remove_index action 2022-01-12 01:12:08 +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
6b21f8dc00 Add missing cleanup assertions to tests 2022-01-04 15:06:40 +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
0fe6569b8c Automatically abort when a migration fails 2022-01-02 02:14:37 +01:00
fabianlindfors
570cf4a84b Extend alter_column_multiple test 2021-12-29 23:34:14 +01:00
fabianlindfors
fda6dc8f40 Add support for generated constraints on columns 2021-12-28 16:01:11 +01:00
fabianlindfors
cbb1834080 Add rename table action 2021-11-17 23:39:03 +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
86f77f497c Add generate-schema-query command 2021-11-11 20:47:07 +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
23034f2198 Add new migration for creating indices 2021-10-27 00:55:29 +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
7d8302a0a4 Initial commit 2021-10-26 00:31:09 +02:00