baza_migrations 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4cb80ba9ce883bc9f98cd144768bd16c7449309f
4
- data.tar.gz: b7658dd52e4fc68b73b2681df789db3cfbb09cfd
3
+ metadata.gz: a5aa2f66c7cd71b586b07bd2a44efdde6ba9cef3
4
+ data.tar.gz: 9b09f3cd13896b16427558bb9d336f5b7e9c7538
5
5
  SHA512:
6
- metadata.gz: 0e776fec6e52acdda85c7be206c8d71fbf7638559830ae5a69634330dbfad9048c4ef84d746300dae61eb8e2a6a1e9a336d9a3c39f30e0b89e08161fe7c93b18
7
- data.tar.gz: 3f2debcb6f02bd4ffde9446243f5acdcd0a76ca1bfd61cbc823453fb80eb5b48f403d8e04eb948e690a5ae1c790dab8fbd3dde9e08c559e98ad040cffa2cd928
6
+ metadata.gz: e004df2c8a66be2e01772a9a2983280cce852fc6155c9803495a8aaadbce9cfe0b5a18735d3fdd0220cf68624d26f6952d965605ca9316cf759921f63c24db4d
7
+ data.tar.gz: 5c25e9e8cbece8e43c09a038a3d8b3bd641a16d36478d9139872606d5f4dbe816a0a73fb09eb95883740f3dc772684410afda8cad7d86e2bfa375b7b654abde0
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,9 @@
1
+
2
+
3
+ # This configuration was generated by
4
+ # `rubocop --auto-gen-config`
5
+ # on 2015-12-20 17:49:37 +0100 using RuboCop version 0.35.1.
6
+ # The point is for the user to remove these configuration records
7
+ # one by one as the offenses are removed from the code base.
8
+ # Note that changes in the inspected code, or installation of new
9
+ # versions of RuboCop, may require this file to be generated again.
data/Gemfile CHANGED
@@ -3,17 +3,23 @@ source "http://rubygems.org"
3
3
  # Example:
4
4
  # gem "activesupport", ">= 2.3.5"
5
5
 
6
- gem "baza", "~> 0.0.14"
6
+ gem "baza", "~> 0.0.20"
7
7
  gem "string-cases", "~> 0.0.1"
8
+ gem "auto_autoloader"
8
9
 
9
10
  # Add dependencies to develop your gem here.
10
11
  # Include everything needed to run rake, tests, features, etc.
11
12
  group :development do
12
- gem "rspec", "~> 2.8.0"
13
+ gem "pry"
14
+ gem "rspec", "~> 3.3.0"
13
15
  gem "rdoc", "~> 3.12"
14
16
  gem "bundler", "~> 1.0"
15
17
  gem "jeweler", "~> 2.0.1"
16
- gem "sqlite3"
18
+ gem "jdbc-sqlite3", platform: :jruby
19
+ gem "sqlite3", platform: :ruby
20
+ gem "wref", "0.0.8"
21
+ gem "rubocop", require: false
22
+ gem "best_practice_project", require: false, github: "kaspernj/best_practice_project"
17
23
  end
18
24
 
19
25
  group :test do
data/Gemfile.lock CHANGED
@@ -1,24 +1,39 @@
1
+ GIT
2
+ remote: git://github.com/kaspernj/best_practice_project.git
3
+ revision: 63faed5527c52b4e0196fcca726df25dc31e0341
4
+ specs:
5
+ best_practice_project (0.0.5)
6
+ psych (~> 2.0.0)
7
+
1
8
  GEM
2
9
  remote: http://rubygems.org/
3
10
  specs:
4
11
  addressable (2.3.7)
5
- array_enumerator (0.0.7)
6
- baza (0.0.14)
7
- array_enumerator
8
- datet
9
- knjrbfw
12
+ array_enumerator (0.0.10)
13
+ ast (2.2.0)
14
+ astrolabe (1.3.1)
15
+ parser (~> 2.2)
16
+ auto_autoloader (0.0.1)
10
17
  string-cases
11
- wref
18
+ baza (0.0.20)
19
+ array_enumerator (~> 0.0.10)
20
+ datet (~> 0.0.25)
21
+ event_handler (~> 0.0.0)
22
+ string-cases (~> 0.0.1)
23
+ wref (~> 0.0.8)
12
24
  builder (3.2.2)
13
25
  codeclimate-test-reporter (0.4.6)
14
26
  simplecov (>= 0.7.1, < 1.0.0)
27
+ coderay (1.1.0)
15
28
  datet (0.0.25)
16
29
  descendants_tracker (0.0.4)
17
30
  thread_safe (~> 0.3, >= 0.3.1)
18
- diff-lcs (1.1.3)
31
+ diff-lcs (1.2.5)
19
32
  docile (1.1.5)
33
+ event_handler (0.0.0)
20
34
  faraday (0.9.1)
21
35
  multipart-post (>= 1.2, < 3)
36
+ ffi (1.9.10-java)
22
37
  git (1.2.9.1)
23
38
  github_api (0.12.3)
24
39
  addressable (~> 2.3)
@@ -30,8 +45,8 @@ GEM
30
45
  oauth2
31
46
  hashie (3.4.0)
32
47
  highline (1.7.1)
33
- http2 (0.0.29)
34
- string-cases
48
+ jar-dependencies (0.3.1)
49
+ jdbc-sqlite3 (3.8.10.1)
35
50
  jeweler (2.0.1)
36
51
  builder
37
52
  bundler (>= 1.0)
@@ -42,66 +57,97 @@ GEM
42
57
  rake
43
58
  rdoc
44
59
  json (1.8.2)
60
+ json (1.8.2-java)
45
61
  jwt (1.3.0)
46
- knjrbfw (0.0.110)
47
- datet
48
- http2
49
- php4r
50
- ruby_process
51
- tsafe
52
- wref
62
+ method_source (0.8.2)
53
63
  mini_portile (0.6.2)
54
64
  multi_json (1.11.0)
55
65
  multi_xml (0.5.5)
56
66
  multipart-post (2.0.0)
57
67
  nokogiri (1.6.6.2)
58
68
  mini_portile (~> 0.6.0)
69
+ nokogiri (1.6.6.2-java)
59
70
  oauth2 (1.0.0)
60
71
  faraday (>= 0.8, < 0.10)
61
72
  jwt (~> 1.0)
62
73
  multi_json (~> 1.3)
63
74
  multi_xml (~> 0.5)
64
75
  rack (~> 1.2)
65
- php4r (0.0.4)
66
- datet
67
- http2
68
- string-strtr
76
+ parser (2.2.3.0)
77
+ ast (>= 1.1, < 3.0)
78
+ powerpack (0.1.1)
79
+ pry (0.10.1)
80
+ coderay (~> 1.1.0)
81
+ method_source (~> 0.8.1)
82
+ slop (~> 3.4)
83
+ pry (0.10.1-java)
84
+ coderay (~> 1.1.0)
85
+ method_source (~> 0.8.1)
86
+ slop (~> 3.4)
87
+ spoon (~> 0.0)
88
+ psych (2.0.16)
89
+ psych (2.0.16-java)
90
+ jar-dependencies (>= 0.1.7)
69
91
  rack (1.6.0)
92
+ rainbow (2.0.0)
70
93
  rake (10.4.2)
71
94
  rdoc (3.12.2)
72
95
  json (~> 1.4)
73
- rspec (2.8.0)
74
- rspec-core (~> 2.8.0)
75
- rspec-expectations (~> 2.8.0)
76
- rspec-mocks (~> 2.8.0)
77
- rspec-core (2.8.0)
78
- rspec-expectations (2.8.0)
79
- diff-lcs (~> 1.1.2)
80
- rspec-mocks (2.8.0)
81
- ruby_process (0.0.9)
82
- tsafe
83
- wref
96
+ rspec (3.3.0)
97
+ rspec-core (~> 3.3.0)
98
+ rspec-expectations (~> 3.3.0)
99
+ rspec-mocks (~> 3.3.0)
100
+ rspec-core (3.3.2)
101
+ rspec-support (~> 3.3.0)
102
+ rspec-expectations (3.3.1)
103
+ diff-lcs (>= 1.2.0, < 2.0)
104
+ rspec-support (~> 3.3.0)
105
+ rspec-mocks (3.3.2)
106
+ diff-lcs (>= 1.2.0, < 2.0)
107
+ rspec-support (~> 3.3.0)
108
+ rspec-support (3.3.0)
109
+ rubocop (0.35.1)
110
+ astrolabe (~> 1.3)
111
+ parser (>= 2.2.3.0, < 3.0)
112
+ powerpack (~> 0.1)
113
+ rainbow (>= 1.99.1, < 3.0)
114
+ ruby-progressbar (~> 1.7)
115
+ tins (<= 1.6.0)
116
+ ruby-progressbar (1.7.5)
84
117
  simplecov (0.9.2)
85
118
  docile (~> 1.1.0)
86
119
  multi_json (~> 1.0)
87
120
  simplecov-html (~> 0.9.0)
88
121
  simplecov-html (0.9.0)
122
+ slop (3.6.0)
123
+ spoon (0.0.4)
124
+ ffi
89
125
  sqlite3 (1.3.10)
90
126
  string-cases (0.0.1)
91
- string-strtr (0.0.3)
92
127
  thread_safe (0.3.4)
93
- tsafe (0.0.11)
94
- wref (0.0.6)
128
+ thread_safe (0.3.4-java)
129
+ tins (1.6.0)
130
+ wref (0.0.8)
95
131
 
96
132
  PLATFORMS
133
+ java
97
134
  ruby
98
135
 
99
136
  DEPENDENCIES
100
- baza (~> 0.0.14)
137
+ auto_autoloader
138
+ baza (~> 0.0.20)
139
+ best_practice_project!
101
140
  bundler (~> 1.0)
102
141
  codeclimate-test-reporter
142
+ jdbc-sqlite3
103
143
  jeweler (~> 2.0.1)
144
+ pry
104
145
  rdoc (~> 3.12)
105
- rspec (~> 2.8.0)
146
+ rspec (~> 3.3.0)
147
+ rubocop
106
148
  sqlite3
107
149
  string-cases (~> 0.0.1)
150
+ wref (= 0.0.8)
151
+
152
+ BUNDLED WITH
153
+ 1.11.2
data/README.md CHANGED
@@ -6,6 +6,14 @@
6
6
 
7
7
  Migrations support for the Baza database framework in Ruby.
8
8
 
9
+ ## Usage
10
+
11
+ ```ruby
12
+ executor = BazaMigrations::MigrationsExecutor.new(db: db)
13
+ executor.add_dir("spec/dummy/db/baza_migrate")
14
+ executor.execute_migrations
15
+ ```
16
+
9
17
  ## Contributing to baza_migrations
10
18
 
11
19
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
@@ -20,4 +28,3 @@ Migrations support for the Baza database framework in Ruby.
20
28
 
21
29
  Copyright (c) 2015 kaspernj. See LICENSE.txt for
22
30
  further details.
23
-
data/Rakefile CHANGED
@@ -1,7 +1,5 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'bundler'
1
+ require "rubygems"
2
+ require "bundler"
5
3
  begin
6
4
  Bundler.setup(:default, :development)
7
5
  rescue Bundler::BundlerError => e
@@ -9,42 +7,45 @@ rescue Bundler::BundlerError => e
9
7
  $stderr.puts "Run `bundle install` to install missing gems"
10
8
  exit e.status_code
11
9
  end
12
- require 'rake'
10
+ require "rake"
13
11
 
14
- require 'jeweler'
12
+ require "jeweler"
15
13
  Jeweler::Tasks.new do |gem|
16
14
  # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
17
15
  gem.name = "baza_migrations"
18
16
  gem.homepage = "http://github.com/kaspernj/baza_migrations"
19
17
  gem.license = "MIT"
20
- gem.summary = %Q{Migrations support for the Baza database framework in Ruby.}
21
- gem.description = %Q{Migrations support for the Baza database framework in Ruby.}
18
+ gem.summary = %(Migrations support for the Baza database framework in Ruby.)
19
+ gem.description = %(Migrations support for the Baza database framework in Ruby.)
22
20
  gem.email = "k@spernj.org"
23
21
  gem.authors = ["kaspernj"]
24
22
  # dependencies defined in Gemfile
25
23
  end
26
24
  Jeweler::RubygemsDotOrgTasks.new
27
25
 
28
- require 'rspec/core'
29
- require 'rspec/core/rake_task'
26
+ require "rspec/core"
27
+ require "rspec/core/rake_task"
30
28
  RSpec::Core::RakeTask.new(:spec) do |spec|
31
- spec.pattern = FileList['spec/**/*_spec.rb']
29
+ spec.pattern = FileList["spec/**/*_spec.rb"]
32
30
  end
33
31
 
34
32
  desc "Code coverage detail"
35
33
  task :simplecov do
36
- ENV['COVERAGE'] = "true"
37
- Rake::Task['spec'].execute
34
+ ENV["COVERAGE"] = "true"
35
+ Rake::Task["spec"].execute
38
36
  end
39
37
 
40
- task :default => :spec
38
+ task default: :spec
41
39
 
42
- require 'rdoc/task'
40
+ require "rdoc/task"
43
41
  Rake::RDocTask.new do |rdoc|
44
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
42
+ version = File.exist?("VERSION") ? File.read("VERSION") : ""
45
43
 
46
- rdoc.rdoc_dir = 'rdoc'
44
+ rdoc.rdoc_dir = "rdoc"
47
45
  rdoc.title = "baza_migrations #{version}"
48
- rdoc.rdoc_files.include('README*')
49
- rdoc.rdoc_files.include('lib/**/*.rb')
46
+ rdoc.rdoc_files.include("README*")
47
+ rdoc.rdoc_files.include("lib/**/*.rb")
50
48
  end
49
+
50
+ require "best_practice_project"
51
+ BestPracticeProject.load_tasks
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: baza_migrations 0.0.0 ruby lib
5
+ # stub: baza_migrations 0.0.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "baza_migrations"
9
- s.version = "0.0.0"
9
+ s.version = "0.0.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib"]
13
13
  s.authors = ["kaspernj"]
14
- s.date = "2015-04-18"
14
+ s.date = "2016-01-06"
15
15
  s.description = "Migrations support for the Baza database framework in Ruby."
16
16
  s.email = "k@spernj.org"
17
17
  s.extra_rdoc_files = [
@@ -21,6 +21,7 @@ Gem::Specification.new do |s|
21
21
  s.files = [
22
22
  ".document",
23
23
  ".rspec",
24
+ ".rubocop_todo.yml",
24
25
  "Gemfile",
25
26
  "Gemfile.lock",
26
27
  "LICENSE.txt",
@@ -28,20 +29,31 @@ Gem::Specification.new do |s|
28
29
  "Rakefile",
29
30
  "VERSION",
30
31
  "baza_migrations.gemspec",
32
+ "config/best_project_practice_rubocop.yml",
33
+ "config/best_project_practice_rubocop_todo.yml",
31
34
  "lib/baza_migrations.rb",
32
35
  "lib/baza_migrations/commands.rb",
36
+ "lib/baza_migrations/commands/add_column.rb",
33
37
  "lib/baza_migrations/commands/add_index.rb",
34
38
  "lib/baza_migrations/commands/base.rb",
35
39
  "lib/baza_migrations/commands/create_table.rb",
36
40
  "lib/baza_migrations/commands/drop_table.rb",
41
+ "lib/baza_migrations/commands/remove_column.rb",
42
+ "lib/baza_migrations/commands/remove_index.rb",
37
43
  "lib/baza_migrations/errors.rb",
44
+ "lib/baza_migrations/migrate.rb",
38
45
  "lib/baza_migrations/migration.rb",
46
+ "lib/baza_migrations/migrations_executor.rb",
39
47
  "lib/tasks/baza.rake",
40
48
  "shippable.yml",
49
+ "spec/dummy/db/baza_migrate/20150901160500_create_users.rb",
50
+ "spec/dummy/db/baza_migrate/20150901161800_create_user_roles.rb",
41
51
  "spec/lib/baza_migrations/migration_spec.rb",
52
+ "spec/lib/baza_migrations/migrations_executor_spec.rb",
42
53
  "spec/spec_helper.rb",
43
54
  "spec/test_classes/201503041644_test_change_migration.rb",
44
- "spec/test_classes/201503041646_test_up_down_migration.rb"
55
+ "spec/test_classes/201503041646_test_up_down_migration.rb",
56
+ "spec/test_classes/201509101727_test_exists_methods.rb"
45
57
  ]
46
58
  s.homepage = "http://github.com/kaspernj/baza_migrations"
47
59
  s.licenses = ["MIT"]
@@ -52,30 +64,48 @@ Gem::Specification.new do |s|
52
64
  s.specification_version = 4
53
65
 
54
66
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
55
- s.add_runtime_dependency(%q<baza>, ["~> 0.0.14"])
67
+ s.add_runtime_dependency(%q<baza>, ["~> 0.0.20"])
56
68
  s.add_runtime_dependency(%q<string-cases>, ["~> 0.0.1"])
57
- s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
69
+ s.add_runtime_dependency(%q<auto_autoloader>, [">= 0"])
70
+ s.add_development_dependency(%q<pry>, [">= 0"])
71
+ s.add_development_dependency(%q<rspec>, ["~> 3.3.0"])
58
72
  s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
59
73
  s.add_development_dependency(%q<bundler>, ["~> 1.0"])
60
74
  s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
75
+ s.add_development_dependency(%q<jdbc-sqlite3>, [">= 0"])
61
76
  s.add_development_dependency(%q<sqlite3>, [">= 0"])
77
+ s.add_development_dependency(%q<wref>, ["= 0.0.8"])
78
+ s.add_development_dependency(%q<rubocop>, [">= 0"])
79
+ s.add_development_dependency(%q<best_practice_project>, [">= 0"])
62
80
  else
63
- s.add_dependency(%q<baza>, ["~> 0.0.14"])
81
+ s.add_dependency(%q<baza>, ["~> 0.0.20"])
64
82
  s.add_dependency(%q<string-cases>, ["~> 0.0.1"])
65
- s.add_dependency(%q<rspec>, ["~> 2.8.0"])
83
+ s.add_dependency(%q<auto_autoloader>, [">= 0"])
84
+ s.add_dependency(%q<pry>, [">= 0"])
85
+ s.add_dependency(%q<rspec>, ["~> 3.3.0"])
66
86
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
67
87
  s.add_dependency(%q<bundler>, ["~> 1.0"])
68
88
  s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
89
+ s.add_dependency(%q<jdbc-sqlite3>, [">= 0"])
69
90
  s.add_dependency(%q<sqlite3>, [">= 0"])
91
+ s.add_dependency(%q<wref>, ["= 0.0.8"])
92
+ s.add_dependency(%q<rubocop>, [">= 0"])
93
+ s.add_dependency(%q<best_practice_project>, [">= 0"])
70
94
  end
71
95
  else
72
- s.add_dependency(%q<baza>, ["~> 0.0.14"])
96
+ s.add_dependency(%q<baza>, ["~> 0.0.20"])
73
97
  s.add_dependency(%q<string-cases>, ["~> 0.0.1"])
74
- s.add_dependency(%q<rspec>, ["~> 2.8.0"])
98
+ s.add_dependency(%q<auto_autoloader>, [">= 0"])
99
+ s.add_dependency(%q<pry>, [">= 0"])
100
+ s.add_dependency(%q<rspec>, ["~> 3.3.0"])
75
101
  s.add_dependency(%q<rdoc>, ["~> 3.12"])
76
102
  s.add_dependency(%q<bundler>, ["~> 1.0"])
77
103
  s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
104
+ s.add_dependency(%q<jdbc-sqlite3>, [">= 0"])
78
105
  s.add_dependency(%q<sqlite3>, [">= 0"])
106
+ s.add_dependency(%q<wref>, ["= 0.0.8"])
107
+ s.add_dependency(%q<rubocop>, [">= 0"])
108
+ s.add_dependency(%q<best_practice_project>, [">= 0"])
79
109
  end
80
110
  end
81
111
 
@@ -0,0 +1,2 @@
1
+ ---
2
+ inherit_from: best_project_practice_rubocop_todo.yml
@@ -0,0 +1,9 @@
1
+
2
+
3
+ # This configuration was generated by
4
+ # `rubocop --auto-gen-config`
5
+ # on 2015-12-20 17:49:37 +0100 using RuboCop version 0.35.1.
6
+ # The point is for the user to remove these configuration records
7
+ # one by one as the offenses are removed from the code base.
8
+ # Note that changes in the inspected code, or installation of new
9
+ # versions of RuboCop, may require this file to be generated again.
@@ -0,0 +1,29 @@
1
+ class BazaMigrations::Commands::AddColumn < BazaMigrations::Commands::Base
2
+ def initialize(table_name, column_name, type)
3
+ @table_name = table_name
4
+ @column_name = column_name
5
+ @type = type
6
+ end
7
+
8
+ def sql
9
+ ["ALTER TABLE `#{@table_name}` ADD COLUMN `#{@column_name}` #{@type};"]
10
+ end
11
+
12
+ def changed_rollback_sql
13
+ sqls = []
14
+ db_type = db.opts.fetch(:type)
15
+
16
+ if db_type.to_s.include?("sqlite3")
17
+ sqls << proc do
18
+ table = db.tables[@table_name]
19
+
20
+ column = table.column(@column_name)
21
+ column.drop
22
+ end
23
+ else
24
+ sqls << "ALTER TABLE `#{@table_name}` DROP COLUMN `#{@column_name}`"
25
+ end
26
+
27
+ sqls
28
+ end
29
+ end
@@ -1,11 +1,14 @@
1
1
  class BazaMigrations::Commands::AddIndex < BazaMigrations::Commands::Base
2
- def initialize(table_name, columns)
2
+ def initialize(table_name, columns, args)
3
3
  @table_name = table_name
4
4
  @columns = columns
5
+ @args = args
5
6
  end
6
7
 
7
8
  def sql
8
- sql = "CREATE INDEX `#{@db.esc_col(index_name)}` ON `#{@db.esc_table(@table_name)}` ("
9
+ sql = "CREATE"
10
+ sql << " UNIQUE" if @args[:unique]
11
+ sql << " INDEX `#{@db.escape_column(index_name)}` ON `#{@db.escape_table(@table_name)}` ("
9
12
 
10
13
  first = true
11
14
  columns_as_array.each do |column|
@@ -20,14 +23,14 @@ class BazaMigrations::Commands::AddIndex < BazaMigrations::Commands::Base
20
23
  end
21
24
 
22
25
  def changed_rollback_sql
23
- ["DROP INDEX IF EXISTS `#{@db.esc_col(index_name)}`"]
26
+ ["DROP INDEX `#{@db.escape_column(index_name)}`"]
24
27
  end
25
28
 
26
29
  private
27
30
 
28
31
  def columns_as_array
29
32
  return @columns if @columns.is_a?(Array)
30
- return [@columns]
33
+ [@columns]
31
34
  end
32
35
 
33
36
  def index_name
@@ -40,6 +43,6 @@ private
40
43
  name << column.to_s
41
44
  end
42
45
 
43
- return name
46
+ name
44
47
  end
45
48
  end
@@ -1,3 +1,11 @@
1
1
  class BazaMigrations::Commands::Base
2
2
  attr_accessor :db, :table
3
+
4
+ def default_args(args = {})
5
+ return_args = {null: true}
6
+ return_args[:null] = args[:null] if args.include?(:null)
7
+ return_args[:default] = args[:default] if args.include?(:default)
8
+
9
+ return_args
10
+ end
3
11
  end
@@ -6,17 +6,33 @@ class BazaMigrations::Commands::CreateTable < BazaMigrations::Commands::Base
6
6
  @columns << {name: :id, type: :int, autoincr: true, primarykey: true}
7
7
  end
8
8
 
9
- def string(name)
10
- @columns << {name: name, type: :string, null: true}
9
+ def string(name, args = {})
10
+ @columns << {name: name, type: :string}.merge(default_args(args))
11
11
  end
12
12
 
13
- def timestamps
14
- @columns << {name: :created_at, type: :datetime, null: true}
15
- @columns << {name: :updated_at, type: :datetime, null: true}
13
+ def text(name, args = {})
14
+ @columns << {name: name, type: :text}.merge(default_args(args))
15
+ end
16
+
17
+ def integer(name, args = {})
18
+ @columns << {name: name, type: :int}.merge(default_args(args))
19
+ end
20
+
21
+ def timestamps(args = {})
22
+ @columns << {name: :created_at, type: :datetime}.merge(default_args(args))
23
+ @columns << {name: :updated_at, type: :datetime}.merge(default_args(args))
24
+ end
25
+
26
+ def belongs_to(name, args = {})
27
+ @columns << {name: "#{name}_id", type: :int, null: true}.merge(default_args(args))
28
+ end
29
+
30
+ def datetime(name, args = {})
31
+ @columns << {name: name, type: :datetime}.merge(default_args(args))
16
32
  end
17
33
 
18
34
  def sql
19
- db.tables.create(@name, {columns: @columns}, {return_sql: true})
35
+ db.tables.create(@name, {columns: @columns}, return_sql: true)
20
36
  end
21
37
 
22
38
  def changed_rollback_sql
@@ -0,0 +1,28 @@
1
+ class BazaMigrations::Commands::RemoveColumn < BazaMigrations::Commands::Base
2
+ def initialize(table_name, column_name)
3
+ @table_name = table_name
4
+ @column_name = column_name
5
+ end
6
+
7
+ def sql
8
+ sqls = []
9
+ db_type = db.opts.fetch(:type)
10
+
11
+ if db_type.to_s.include?("sqlite3")
12
+ sqls << proc do
13
+ table = db.tables[@table_name]
14
+
15
+ column = table.column(@column_name)
16
+ column.drop
17
+ end
18
+ else
19
+ sqls << "ALTER TABLE `#{@table_name}` DROP COLUMN `#{@column_name}`"
20
+ end
21
+
22
+ sqls
23
+ end
24
+
25
+ def changed_rollback_sql
26
+ raise BazaMigrations::Errors::IrreversibleMigration
27
+ end
28
+ end
@@ -0,0 +1,33 @@
1
+ class BazaMigrations::Commands::RemoveIndex < BazaMigrations::Commands::Base
2
+ def initialize(table_name, column_name)
3
+ @table_name = table_name
4
+
5
+ if column_name.is_a?(Array)
6
+ @index_name = "index_#{@table_name}_on_#{column_name.join("_and_")}"
7
+ else
8
+ @index_name = "index_#{@table_name}_on_#{column_name}"
9
+ end
10
+ end
11
+
12
+ def sql
13
+ sqls = []
14
+ db_type = db.opts.fetch(:type)
15
+
16
+ if db_type.to_s.include?("sqlite3")
17
+ sqls << proc do
18
+ table = db.tables[@table_name]
19
+
20
+ index = table.index(@index_name)
21
+ index.drop
22
+ end
23
+ else
24
+ sqls << "DROP INDEX `#{@index_name}` ON `#{@table_name}`"
25
+ end
26
+
27
+ sqls
28
+ end
29
+
30
+ def changed_rollback_sql
31
+ raise BazaMigrations::Errors::IrreversibleMigration
32
+ end
33
+ end
@@ -1,10 +1,3 @@
1
1
  class BazaMigrations::Commands
2
- path = "#{File.dirname(__FILE__)}/commands"
3
-
4
- autoload :AddIndex, "#{path}/add_index"
5
- autoload :Base, "#{path}/base"
6
- autoload :CreateTable, "#{path}/create_table"
7
- autoload :DropTable, "#{path}/drop_table"
8
- autoload :AddColumn, "#{path}/add_column"
9
- autoload :RemoveColumn, "#{path}/remove_column"
2
+ AutoAutoloader.autoload_sub_classes(self, __FILE__)
10
3
  end