Commit Graph

114 Commits

Author SHA1 Message Date
fabianlindfors
814620a215 Add new add_foreign_key action 2022-01-21 18:00:41 +01:00
fabianlindfors
9d1b7c4082 Use helper function to find column in table 2022-01-21 17:14:12 +01:00
fabianlindfors
b6f1a0c6a4 Use real table and column names for foreign keys in create_table 2022-01-21 17:07:46 +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
b3766ba2b6 Add link to blog post to README 2022-01-16 23:24:29 +01:00
fabianlindfors
49b01bbb28 Version 0.3.1 2022-01-16 23:00:46 +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
35a52ebd81 Fix issue where changes had to be set for alter_column
Some type of changes don't require anything in `changes`, for example
when changing the values of a column with `up` and `down`.
2022-01-15 15:53:55 +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
0e0c24b789 Adjust README introduction and disclaimer
Tones down the disclaimer a bit as I feel reasonable certain Reshape
won't lose any data. Also adds some details about locking and downtime
to the introduction.
2022-01-14 13:14:16 +01:00
fabianlindfors
f3ead43cde Bump Dockerfile Rust version to 1.58 2022-01-14 12:59:01 +01:00
fabianlindfors
17376ce3b7 Version 0.3.0 2022-01-14 12:38:21 +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
d28110611c Fix clippy warnings 2022-01-14 00:12:57 +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
b1b79e26e5 Store version under separate key in reshape.data table
The version is not currently in used but will probably be useful later
when we want Reshape to be backwards compatbility. Having the version
stored in the database will then allow us to perform schema migrations
on the metadata of Reshape.
2022-01-13 23:56:06 +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
b86e6d53ca Run lint and test actions on PR 2022-01-13 14:32:57 +01:00
Fabian Lindfors
d76dbab5ba
Merge pull request #3 from barrywoolgar/patch-1
Explain the new concept at the top of the README
2022-01-13 14:27:24 +01:00
Barry Woolgar
b3ead8b2e2
Explain the new concept at the top of the README
This allows people new to the project to understand how Reshape works before getting into the technical detail of setting it up and using it (which they may or may not want to do just yet).
2022-01-13 10:36:25 +00:00
fabianlindfors
9cd9bd395b Add quotes for all identifiers in queries 2022-01-13 00:34:42 +01:00
fabianlindfors
0dd8272e9f Publish to crates.io with each release 2022-01-13 00:07:43 +01:00
fabianlindfors
24e1d4b902 Version 0.2.0 2022-01-12 13:19:27 +01:00
fabianlindfors
c787111c77 Remove transaction from abort
All migrations can be aborted idempotently at the moment and hence we
don't need to use a transaction for atomicity.
2022-01-12 13:15:26 +01:00
fabianlindfors
b617c8dcda Drop index concurrently when aborting add_index 2022-01-12 01:13:23 +01:00
fabianlindfors
480bcf8af1 Add remove_index action 2022-01-12 01:12:08 +01:00
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