Commit graph

14 commits

Author SHA1 Message Date
blackst0ne
9997c58fc0 Add remove_concurrent_index to database helper 2017-04-06 09:53:57 +11:00
Yorick Peterse
79696f5b7a
Hash concurrent foreign key names similar to Rails
This was initially not implemented simply because I forgot about the
size limit of constraint names in PostgreSQL (63 bytes). Using the old
technique we can't add foreign keys for certain tables. For example,
adding a foreign key on
protected_branch_merge_access_levels.protected_branch_id would lead to
the following key name:

    fk_protected_branch_merge_access_levels_protected_branches_protected_branch_id

This key is 78 bytes long, thus violating the PostgreSQL size
requirements.

The hashing strategy is copied from Rails' foreign_key_name() method,
which unfortunately is private and subject to change without notice.
2017-02-21 15:07:02 +01:00
Yorick Peterse
a97dcc077c
Add method for creating foreign keys concurrently
This method allows one to create foreign keys without blocking access to
the source table, but only on PostgreSQL.

When creating a regular foreign key the "ALTER TABLE" statement used for
this won't return until all data has been validated. This statement in
turn will acquire a lock on the source table. As a result this lock can
be held for quite a long amount of time, depending on the number of rows
and system load.

By breaking up the foreign key creation process in two steps (creation,
and validation) we can reduce the amount of locking to a minimum.
Locking is still necessary for the "ALTER TABLE" statement that adds the
constraint, but this is a fast process and so will only block access for
a few milliseconds.
2017-02-10 21:51:09 +01:00
Drew Blessing
1f399fe437 fix 2016-09-15 21:59:59 -05:00
Drew Blessing
e000f02bd3 Add support for column limits in add_column_with_default 2016-09-15 21:59:58 -05:00
Stan Hu
3fd304c1a5 Fix spec Don't attempt to disable statement timeout on a MySQL DB 2016-07-14 20:55:33 -07:00
Yorick Peterse
816c453558
Don't update columns in batches in a transaction
This ensures that whatever locks are acquired aren't held onto until the
end of the transaction (= after _all_ rows have been updated). Timing
wise there's also no difference between using a transaction and not
using one.
2016-06-15 17:04:07 +02:00
Yorick Peterse
8966263e0c
Customizing of update_column_in_batches queries
By passing a block to update_column_in_batches() one can now customize
the queries executed. This in turn can be used to only update a specific
set of rows instead of simply all the rows in the table.
2016-06-15 16:44:44 +02:00
Yorick Peterse
b33b7be53e
Handle NULL migration errors in migration helpers
This ensures that whenever changing the NULL constraint of a column
fails we still drop the column.
2016-06-13 11:22:58 +02:00
Felipe Artur
9264203103 change add_concurrent_index function arguments 2016-06-06 13:06:21 -03:00
Grzegorz Bizon
9e92b0eead Add specs for migration helpers and boolean values 2016-05-22 22:41:14 +02:00
Grzegorz Bizon
13bf612600 Test migration helpers using a migration class 2016-05-22 22:40:43 +02:00
Yorick Peterse
36083b4d0e
Fixed styling per Rubocop pedantics 2016-05-12 13:03:55 +02:00
Yorick Peterse
e867099091
Added helper methods for database migrations
These helpers can be used to perform migrations without taking down the
entire application.

For example, the method "add_column_with_default" can be used to add a
new column with a default value without locking the entire table.
2016-05-12 12:59:40 +02:00