nondestructive_migrations 1.0 → 1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- NzNiMWEyMDA5MGNlMjFhOWYwOWM0Yzk2MGRhNzkzNzJlZGMwODVlMg==
5
- data.tar.gz: !binary |-
6
- OTQ4YTk5Y2M4NDU1ODMzYTJlZDgzZGM0ODdjZmFhYjg3NTVhNzBiNg==
2
+ SHA1:
3
+ metadata.gz: 52efa8e5de4b6c6e944b2f49f50bc6b8c36f15cc
4
+ data.tar.gz: bab0c62fa9b1c21b00b3b9f9e9d5001df7ce47c8
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- YTQzZTgwZTM2NDJmYmJjN2U0ZGI5NWM1YjQyNDJhNDkzZjZjYjU5YTI0ODUw
10
- ZDM4N2E4OTMyZWQwOTFlNWExOTFmYTI1ZDkxZjNmMjNlYWE4ZDQyNGMzNzcy
11
- ZTc1MTA3MjE0YzhkZmE0OWJmNzQyMzkzZmEzNTc1NjU5YTI2MzM=
12
- data.tar.gz: !binary |-
13
- ZmQyYTkyZTg1Yjc2NzZkZWY5ODc1NWQzYWI1MjY0NDdmN2EyYjUxMTk3MzFk
14
- MTBkZWMxOGQ2ZjA5YWZmZTUxMjI2MTI1OGNhMTEyMjBjMGQxNjhlZjc5YzVi
15
- OTA4YzY2OWJkMTYzMTFmMjFiZTM1YTBkYWUzZTI4MWQ5ZmZmMTU=
6
+ metadata.gz: dc9c38949a5f361b4cf70ddef8282df6301745bd2bb45e2b1742e5f58f0713f75b4fad42d518bd2c28a8e2d9b7b6b155b94b46d9c4eeb1fd18e7dc6f6c962215
7
+ data.tar.gz: 434c533281a6546d3b3c453e333c958adae75e21539657c6d48f17fa7a48ac25ebe40e2257ef9f5b52ea4c05c621c27140213f5f44e7c56c3790de9074804dcc
@@ -0,0 +1,52 @@
1
+ require 'active_record/scoping/default'
2
+ require 'active_record/scoping/named'
3
+ require 'active_record/base'
4
+
5
+ module ActiveRecord
6
+ class DataMigration < ActiveRecord::Base
7
+ class << self
8
+ def primary_key
9
+ nil
10
+ end
11
+
12
+ def table_name
13
+ "#{table_name_prefix}data_migrations#{table_name_suffix}"
14
+ end
15
+
16
+ def index_name
17
+ "#{table_name_prefix}unique_data_migrations#{table_name_suffix}"
18
+ end
19
+
20
+ def table_exists?
21
+ connection.table_exists?(table_name)
22
+ end
23
+
24
+ def create_table(limit=nil)
25
+ unless table_exists?
26
+ version_options = {null: false}
27
+ version_options[:limit] = limit if limit
28
+
29
+ connection.create_table(table_name, id: false) do |t|
30
+ t.column :version, :string, version_options
31
+ end
32
+ connection.add_index table_name, :version, unique: true, name: index_name
33
+ end
34
+ end
35
+
36
+ def drop_table
37
+ if table_exists?
38
+ connection.remove_index table_name, name: index_name
39
+ connection.drop_table(table_name)
40
+ end
41
+ end
42
+
43
+ def normalize_migration_number(number)
44
+ "%.3d" % number.to_i
45
+ end
46
+ end
47
+
48
+ def version
49
+ super.to_i
50
+ end
51
+ end
52
+ end
@@ -3,6 +3,7 @@ MIGRATIONS_PATH = 'db/data_migrate'
3
3
 
4
4
  require 'generators/data_migration_install_generator.rb'
5
5
  require 'generators/data_migration_generator.rb'
6
+ require 'active_record/data_migration.rb'
6
7
  require 'nondestructive_migrator.rb'
7
8
 
8
9
  module NondestructiveMigrations
@@ -1,5 +1,5 @@
1
1
  require 'nondestructive_migrations'
2
- require 'rails'
2
+
3
3
 
4
4
  module DataMigrations
5
5
  class Railtie < Rails::Railtie
@@ -1,13 +1,42 @@
1
+
2
+
3
+
1
4
  class NondestructiveMigrator < ActiveRecord::Migrator
2
5
  # This class related to data migration.
3
6
  # Used in rake tasks (rake data:[migrate|rollback|up|down])
7
+
8
+ def record_version_state_after_migrating(version)
9
+ if down?
10
+ migrated.delete(version)
11
+ ActiveRecord::DataMigration.where(:version => version.to_s).delete_all
12
+ else
13
+ migrated << version
14
+ ActiveRecord::DataMigration.create!(:version => version.to_s)
15
+ end
16
+ end
17
+
18
+
4
19
  class <<self
5
20
  def migrations_path
6
21
  MIGRATIONS_PATH
7
22
  end
8
-
23
+
9
24
  def schema_migrations_table_name
10
25
  'data_migrations'
11
26
  end
27
+
28
+ def schema_migrations_table_name
29
+ ActiveRecord::DataMigration.table_name
30
+ end
31
+
32
+ def get_all_versions(connection = ActiveRecord::Base.connection)
33
+ if connection.table_exists?(schema_migrations_table_name)
34
+ ActiveRecord::DataMigration.all.map { |x| x.version.to_i }.sort
35
+ else
36
+ []
37
+ end
38
+ end
12
39
  end
13
40
  end
41
+
42
+
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: nondestructive_migrations
3
3
  version: !ruby/object:Gem::Version
4
- version: '1.0'
4
+ version: '1.1'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Fleetwood-Boldt
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-27 00:00:00.000000000 Z
11
+ date: 2015-03-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '4.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>='
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '4.0'
27
27
  description: Separate schema-only migrations from nondestrucitve (data) migrations
28
28
  in your Rails app
29
29
  email: jason@datatravels.com
@@ -31,6 +31,7 @@ executables: []
31
31
  extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
+ - lib/active_record/data_migration.rb
34
35
  - lib/generators/data_migration_generator.rb
35
36
  - lib/generators/data_migration_install_generator.rb
36
37
  - lib/generators/templates/create_data_migrations.rb
@@ -48,19 +49,18 @@ require_paths:
48
49
  - lib
49
50
  required_ruby_version: !ruby/object:Gem::Requirement
50
51
  requirements:
51
- - - ! '>='
52
+ - - ">="
52
53
  - !ruby/object:Gem::Version
53
54
  version: '0'
54
55
  required_rubygems_version: !ruby/object:Gem::Requirement
55
56
  requirements:
56
- - - ! '>='
57
+ - - ">="
57
58
  - !ruby/object:Gem::Version
58
59
  version: '0'
59
60
  requirements: []
60
61
  rubyforge_project:
61
- rubygems_version: 2.2.2
62
+ rubygems_version: 2.4.3
62
63
  signing_key:
63
64
  specification_version: 4
64
65
  summary: Nondestructive (data-only) migrations for your Rails app
65
66
  test_files: []
66
- has_rdoc: