-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathREADME
49 lines (36 loc) · 1.89 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
NOTICE: Repository moved to https://github.com/MakeYourLaws/mysql_big_table_migration
MysqlBigTableMigration
======================
A Rails plugin that adds methods to ActiveRecord::Migration to allow columns
and indexes to be added to and removed from large tables with millions of
rows in MySQL, without leaving processes seemingly stalled in state "copy
to tmp table".
For each of the standard transformations that operate on columns or indexes,
this plugin adds a "using_tmp_table" version. These methods create a
temporary table with the same structure as the table to be altered, applies
the transformation to the temp table, copies data from the source table to
the temp table and then replaces the source table with the temporary one.
While it does try to ensure that data is consistent at the end of the entire
process by locking tables and looking for rows created or modified during
copying, this is NOT TRANSACTION SAFE as it (a) relies on timestamp columns
and (b) doesn't handle rows that have been deleted from the source table
after being copied to the temporary table.
Example
=======
class AddIndexOnSomeColumnToSomeTable < ActiveRecord::Migration
def self.up
add_index_using_tmp_table :some_table, :some_column
end
def self.down
remove_index_using_tmp_table :some_table, :some_column
end
end
Copyright (c) 2010 Mark Woods, released under the MIT license
Testing
========
You will need to bundle install dependencies for the project, as well as create a test database. To install dependencies run `bundle install`. To create the database run the following in a MySQL prompt as an admin user:
```
CREATE DATABASE mysql_big_table_migration_test;
GRANT ALL PRIVILEGES ON *.* TO 'dev'@'localhost' IDENTIFIED BY 'password';
```
After bundling dependencies, and setting up the test database, run the tests with `rake test`