ryakuzu 0.2.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (100) hide show
  1. checksums.yaml +7 -0
  2. data/Rakefile +37 -0
  3. data/app/assets/javascripts/ryakuzu/application.js +15 -0
  4. data/app/assets/javascripts/ryakuzu/update_schema.coffee +14 -0
  5. data/app/assets/stylesheets/ryakuzu/application.sass +61 -0
  6. data/app/controllers/ryakuzu/main_controller.rb +9 -0
  7. data/app/controllers/ryakuzu/root_controller.rb +16 -0
  8. data/app/controllers/ryakuzu/tables_controller.rb +71 -0
  9. data/app/models/ryakuzu/column.rb +41 -0
  10. data/app/models/ryakuzu/column_defaults.rb +17 -0
  11. data/app/models/ryakuzu/schema.rb +11 -0
  12. data/app/models/ryakuzu/table.rb +29 -0
  13. data/app/services/ryakuzu/add_column_service.rb +22 -0
  14. data/app/services/ryakuzu/column_default_service.rb +64 -0
  15. data/app/services/ryakuzu/column_service.rb +22 -0
  16. data/app/services/ryakuzu/create_table_service.rb +34 -0
  17. data/app/services/ryakuzu/migration_service.rb +29 -0
  18. data/app/services/ryakuzu/remove_service.rb +26 -0
  19. data/app/services/ryakuzu/run_migration.rb +43 -0
  20. data/app/services/ryakuzu/table_service.rb +19 -0
  21. data/app/views/ryakuzu/layouts/_cdn.erb +3 -0
  22. data/app/views/ryakuzu/layouts/_header.html.slim +13 -0
  23. data/app/views/ryakuzu/layouts/_preload.html.slim +30 -0
  24. data/app/views/ryakuzu/layouts/application.html.slim +31 -0
  25. data/app/views/ryakuzu/main/_add_column_form.html.slim +5 -0
  26. data/app/views/ryakuzu/main/_add_table_form.html.slim +5 -0
  27. data/app/views/ryakuzu/main/_column_form.html.slim +5 -0
  28. data/app/views/ryakuzu/main/error_500.html.slim +1 -0
  29. data/app/views/ryakuzu/main/index.html.slim +35 -0
  30. data/app/views/ryakuzu/tables/_add_column.html.slim +9 -0
  31. data/app/views/ryakuzu/tables/_add_table.html.slim +9 -0
  32. data/app/views/ryakuzu/tables/_column.html.slim +16 -0
  33. data/app/views/ryakuzu/tables/_input.html.slim +6 -0
  34. data/app/views/ryakuzu/tables/add_column.js.erb +2 -0
  35. data/app/views/ryakuzu/tables/add_column_form.js.erb +2 -0
  36. data/app/views/ryakuzu/tables/add_table.js.erb +3 -0
  37. data/app/views/ryakuzu/tables/column.js.erb +2 -0
  38. data/app/views/ryakuzu/tables/column_options.js.erb +2 -0
  39. data/app/views/ryakuzu/tables/create.js.erb +1 -0
  40. data/app/views/ryakuzu/tables/create_table.js.erb +2 -0
  41. data/app/views/ryakuzu/tables/new_column.js.erb +1 -0
  42. data/app/views/ryakuzu/tables/remove_column.js.erb +2 -0
  43. data/config/routes.rb +16 -0
  44. data/lib/ryakuzu/boolean_patch.rb +35 -0
  45. data/lib/ryakuzu/column_info.rb +54 -0
  46. data/lib/ryakuzu/engine.rb +8 -0
  47. data/lib/ryakuzu/ripper.rb +30 -0
  48. data/lib/ryakuzu/schema_extenstions.rb +19 -0
  49. data/lib/ryakuzu/schema_service.rb +67 -0
  50. data/lib/ryakuzu/version.rb +3 -0
  51. data/lib/ryakuzu.rb +4 -0
  52. data/lib/tasks/ryakuzu_tasks.rake +4 -0
  53. data/test/dummy/README.rdoc +28 -0
  54. data/test/dummy/Rakefile +6 -0
  55. data/test/dummy/app/assets/javascripts/application.js +13 -0
  56. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  57. data/test/dummy/app/controllers/application_controller.rb +5 -0
  58. data/test/dummy/app/helpers/application_helper.rb +2 -0
  59. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  60. data/test/dummy/bin/bundle +3 -0
  61. data/test/dummy/bin/rails +4 -0
  62. data/test/dummy/bin/rake +4 -0
  63. data/test/dummy/bin/setup +29 -0
  64. data/test/dummy/config/application.rb +26 -0
  65. data/test/dummy/config/boot.rb +5 -0
  66. data/test/dummy/config/database.yml +25 -0
  67. data/test/dummy/config/environment.rb +5 -0
  68. data/test/dummy/config/environments/development.rb +41 -0
  69. data/test/dummy/config/environments/production.rb +79 -0
  70. data/test/dummy/config/environments/test.rb +42 -0
  71. data/test/dummy/config/initializers/assets.rb +11 -0
  72. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  73. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  74. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  75. data/test/dummy/config/initializers/inflections.rb +16 -0
  76. data/test/dummy/config/initializers/mime_types.rb +4 -0
  77. data/test/dummy/config/initializers/session_store.rb +3 -0
  78. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  79. data/test/dummy/config/locales/en.yml +23 -0
  80. data/test/dummy/config/routes.rb +4 -0
  81. data/test/dummy/config/secrets.yml +22 -0
  82. data/test/dummy/config.ru +4 -0
  83. data/test/dummy/db/schema.rb +135 -0
  84. data/test/dummy/db/test.sqlite3 +0 -0
  85. data/test/dummy/log/test.log +8602 -0
  86. data/test/dummy/public/404.html +67 -0
  87. data/test/dummy/public/422.html +67 -0
  88. data/test/dummy/public/500.html +66 -0
  89. data/test/dummy/public/favicon.ico +0 -0
  90. data/test/integration/navigation_test.rb +8 -0
  91. data/test/lib/column_info_test.rb +23 -0
  92. data/test/lib/schema_service_test.rb +27 -0
  93. data/test/ryakuzu_test.rb +7 -0
  94. data/test/services/add_column_service_test.rb +10 -0
  95. data/test/services/column_default_service_test.rb +10 -0
  96. data/test/services/column_service_test.rb +10 -0
  97. data/test/services/run_migration_test.rb +15 -0
  98. data/test/services/table_service_test.rb +13 -0
  99. data/test/test_helper.rb +21 -0
  100. metadata +287 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 266157c99b8fb6dea28cc318008247ea8ac0e828
4
+ data.tar.gz: 663cdedc7d856581c9e0fe52966264d1a0efa0fd
5
+ SHA512:
6
+ metadata.gz: 1812949e8c808195330164e52a59b2e91d1275057eba33c2f53a2fb20015c15890799f550aee1915d9d9ef49ab32aeffb1d1809dd9c5737173606529c60e915a
7
+ data.tar.gz: 804b7de183dbaabd3b4c85ad3ef0408bab4f4972de38e26113641d0601fb3c2b4a762850ec68b0df274ef5c1ad94707b30305a4766c2edd34ce656e23a72d8ac
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'Ryakuzu'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'test'
32
+ t.pattern = 'test/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+
37
+ task default: :test
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,14 @@
1
+ $ ->
2
+ $('#loading').hide()
3
+
4
+ $(document).on 'ajaxStart', ->
5
+ $('#loading').show()
6
+ $('body').addClass('dark')
7
+
8
+ $(document).on 'ajaxStop', ->
9
+ $('#loading').hide()
10
+ $('body').removeClass('dark')
11
+
12
+ $('p#close-modal').on 'click', ->
13
+ $('#modal1, #modal2, #modal3').closeModal()
14
+ $('.lean-overlay').remove()
@@ -0,0 +1,61 @@
1
+ input[type=text], input[type=password], input[type=email], input[type=url], input[type=time], input[type=date], input[type=datetime-local], input[type=tel], input[type=number], input[type=search], textarea.materialize-textarea
2
+ font-size: 1.3rem
3
+
4
+ label
5
+ font-size: 1.3rem
6
+ color: #6D6D6D
7
+
8
+ .option-button
9
+ &:before
10
+ content: '+'
11
+ font-size: 24px
12
+ padding: 11px
13
+ &:hover:before
14
+ color: white
15
+
16
+ a
17
+ &:hover
18
+ text-decoration: none
19
+
20
+ .notice
21
+ padding: 20px
22
+ background: antiquewhite
23
+ border-radius: 10px
24
+ margin: 0px 0px 25px 0px
25
+ font-size: 16px
26
+ color: black
27
+
28
+ .logo
29
+ width: 85%
30
+
31
+ #text-logo
32
+ color: slateblue
33
+
34
+ #loading
35
+ position: absolute
36
+ top: 50%
37
+ left: 50%
38
+ z-index: 99999999
39
+
40
+ #modal1, #modal2, #modal3
41
+ z-index: 5000
42
+
43
+ .dark
44
+ position: fixed
45
+ top: 0
46
+ bottom: 0
47
+ left: 0
48
+ right: 0
49
+ background-color: #fff
50
+ opacity: 0.7
51
+ z-index: 1001
52
+
53
+ .modal
54
+ background: none
55
+ box-shadow: none
56
+ overflow-y: overlay
57
+
58
+ #close-modal
59
+ font-size: 18px
60
+ &:hover
61
+ cursor: pointer
@@ -0,0 +1,9 @@
1
+ module Ryakuzu
2
+ class MainController < RootController
3
+ def index
4
+ schema = Ryakuzu::SchemaService.new
5
+ @schema = schema.hash.as_json
6
+ render template: 'ryakuzu/main/index', layout: 'ryakuzu/layouts/application'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,16 @@
1
+ module Ryakuzu
2
+ class RootController < ActionController::Base
3
+ rescue_from Errno::ENOENT, with: :render_500
4
+ helper_method :schema_present?
5
+
6
+ private
7
+
8
+ def render_500
9
+ render template: 'ryakuzu/main/error_500', layout: 'ryakuzu/layouts/application', status: 500
10
+ end
11
+
12
+ def schema_present?
13
+ File.file?('db/schema.rb')
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,71 @@
1
+ module Ryakuzu
2
+ class TablesController < RootController
3
+ def create
4
+ result = Ryakuzu::MigrationService.new(params[:table]).call
5
+ responds_to(result)
6
+ end
7
+
8
+ def column
9
+ @column = params[:column]
10
+ @table = params[:table]
11
+ @opts = Ryakuzu::ColumnInfo.new.call(@table, @column)
12
+ responds_to(@opts)
13
+ end
14
+
15
+ def column_options
16
+ result = Ryakuzu::ColumnDefaultService.new(params[:column_defaults]).call
17
+ responds_to(result)
18
+ end
19
+
20
+ def remove_column
21
+ result = Ryakuzu::RemoveService.new(table: params[:table], column: params[:column]).call
22
+ responds_to(result)
23
+ end
24
+
25
+ def remove_table
26
+ result = Ryakuzu::RemoveService.new(table: params[:table]).call
27
+ redirect_to :back, notice: result
28
+ end
29
+
30
+ def add_column_form
31
+ @table = params[:table]
32
+ responds_to(@table)
33
+ end
34
+
35
+ def add_column
36
+ table = params[:table]
37
+ column = params[:name]['column']
38
+ type = params[:type]
39
+ result = Ryakuzu::AddColumnService.new(table, column, type).call
40
+ responds_to(result)
41
+ end
42
+
43
+ def add_table; end
44
+
45
+ def new_column; end
46
+
47
+ def save_csv
48
+ schema = Ryakuzu::SchemaService.new
49
+ schema.call
50
+ schema.schema_to_csv
51
+ File.open('schema.csv', 'r') do |f|
52
+ send_data f.read, type: 'text/csv', filename: 'schema.csv'
53
+ end
54
+ File.delete('schema.csv')
55
+ end
56
+
57
+ def create_table
58
+ result = Ryakuzu::CreateTableService.new(params[:table], params[:column], params[:type]).call
59
+ responds_to(result)
60
+ end
61
+
62
+ private
63
+
64
+ def responds_to(variable)
65
+ respond_to do |format|
66
+ format.html
67
+ format.js { variable }
68
+ end
69
+ end
70
+ end
71
+ end
@@ -0,0 +1,41 @@
1
+ module Ryakuzu
2
+ class Column < Schema
3
+ attr_accessor :hash, :table, :column, :default, :type, :null, :index
4
+
5
+ def initialize(hash = {})
6
+ @hash = hash
7
+ @table = hash[:table]
8
+ @column = hash[:column]
9
+ @default = hash[:default]
10
+ @type = hash[:type]
11
+ @null = hash[:null]
12
+ end
13
+
14
+ def column_info
15
+ @null = to_boolean(null)
16
+ Ryakuzu::ColumnDefaults.new(hash, null)
17
+ end
18
+
19
+ private
20
+
21
+ def to_boolean(str)
22
+ str == 'true'
23
+ end
24
+
25
+ =begin
26
+ def check_index
27
+ @index = index.split
28
+ index_hash = create_hash(@index)
29
+ h2 = hash.reject! { |_k, v| v.nil? }
30
+ (index_hash && h2) ? (index_hash.keys.first == h2[:table] && index_hash.values.first == h2[:column]) : (false)
31
+ end
32
+
33
+ def create_hash(hash_i)
34
+ indx = hash_i.each_with_object(Hash.new(0)) { |i, hash| hash[i] = i }
35
+ new_hash = {}
36
+ new_hash[indx.keys.first[0]] = indx.keys.first[1].delete!('[').delete!(']')
37
+ new_hash
38
+ end
39
+ =end
40
+ end
41
+ end
@@ -0,0 +1,17 @@
1
+ module Ryakuzu
2
+ class ColumnDefaults < Schema
3
+ attr_accessor :table, :column, :default, :type, :null, :index
4
+
5
+ attribute :table, String
6
+ attribute :column, String
7
+ attribute :default, String
8
+ attribute :type, String
9
+ attribute :null, String
10
+ attribute :index, Boolean
11
+
12
+ def initialize(hash, null)
13
+ hash.each { |key, val| send("#{key}=", val) }
14
+ self.default = '""' if default == ""
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,11 @@
1
+ module Ryakuzu
2
+ class Schema
3
+ require 'virtus/relations'
4
+ include Virtus.model
5
+ include ActiveModel::Conversion
6
+ extend ActiveModel::Naming
7
+
8
+ def persisted?
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ module Ryakuzu
2
+ class Table < Schema
3
+ include Virtus.relations(as: :table)
4
+
5
+ attribute :name, String
6
+ attribute :column, Ryakuzu::Column, relation: true
7
+
8
+ class << self
9
+ def generate_models(key, value)
10
+ hash_handler(key, value, false)
11
+ end
12
+
13
+ def create_model(schema)
14
+ hash_handler(schema['name'], schema['column'], true)
15
+ end
16
+
17
+ def hash_handler(table_name, kolumn, index)
18
+ table = Ryakuzu::Table.new(name: table_name)
19
+ column = Ryakuzu::Column.new
20
+ column.extend(Virtus.model)
21
+ kolumn.each_with_index do |value, indx|
22
+ column.attribute "column_#{indx}".to_sym, String, default: (index == true) ? value[1] : value, lazy: true
23
+ end
24
+ table.column = column
25
+ table
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ module Ryakuzu
2
+ class AddColumnService
3
+ attr_reader :table, :column, :type
4
+
5
+ def initialize(table, column, type)
6
+ @table = table
7
+ @column = column
8
+ @type = type
9
+ end
10
+
11
+ def call
12
+ text = text_migration
13
+ Ryakuzu::RunMigration.new(new_column: column).call(table, text, 'table')
14
+ end
15
+
16
+ private
17
+
18
+ def text_migration
19
+ "add_column :#{table.tableize}, :#{column}, :#{type.downcase.to_sym}"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,64 @@
1
+ require_relative '../../../lib/ryakuzu/boolean_patch'
2
+
3
+ module Ryakuzu
4
+ class ColumnDefaultService
5
+ attr_reader :params, :default, :index, :null, :type, :table, :column,
6
+ :old_null, :old_default, :parameters, :old_type
7
+
8
+ def initialize(params)
9
+ @params = params
10
+ @parameters = params['parameters']
11
+ @default = params['default']
12
+ @index = params['index']
13
+ @null = params['null']
14
+ @type = params['type']
15
+ @table = params['table']
16
+ @column = params['column']
17
+ @old_type = params['parameters'][':old_type']
18
+ @old_default = params['parameters'][':old_default']
19
+ end
20
+
21
+ def call
22
+ processing_params
23
+ current = params.reject { |k, _v| %w(table column).include? k }.except('parameters')
24
+
25
+ zip = current.zip(params['parameters'])
26
+
27
+ zip.each do |k, v|
28
+ run_column_default_migration(k, table, column) if k[1] != v[1]
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def processing_params
35
+ # TODO: make index and null select
36
+ [null, index, old_null].each do |key|
37
+ case key
38
+ when 'none' then 'none'
39
+ when true then true
40
+ when false then false
41
+ end
42
+ end
43
+
44
+ @default = '' if default == "\"\""
45
+ @old_default = '' if old_default == "\"\""
46
+ type.gsub!('Current: ', '')
47
+ end
48
+
49
+ def run_column_default_migration(type_column, tabl, kolumn)
50
+ text = remove_column_text(tabl, kolumn, type_column)
51
+ p tabl
52
+ p kolumn
53
+ p type_column
54
+
55
+ Ryakuzu::RunMigration.new(table: tabl, column: kolumn).call(kolumn, text, 'column')
56
+ end
57
+
58
+ def remove_column_text(tabl, kolumn, type_column)
59
+ type_kolumn = type_column[1].downcase.to_sym
60
+ text = "remove_column :#{tabl.tableize}, :#{kolumn}\n"
61
+ text.concat "add_column :#{tabl.tableize}, :#{kolumn}, :#{type_kolumn}"
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,22 @@
1
+ module Ryakuzu
2
+ class ColumnService
3
+ attr_accessor :old_column, :new_column, :table
4
+
5
+ def initialize(old_column, new_column, table)
6
+ @old_column = old_column
7
+ @new_column = new_column
8
+ @table = table
9
+ end
10
+
11
+ def call
12
+ text = text_migration
13
+ Ryakuzu::RunMigration.new(old_column: old_column, new_column: new_column).call(new_column, text, 'column')
14
+ end
15
+
16
+ private
17
+
18
+ def text_migration
19
+ "rename_column :#{table.tableize}, :#{old_column}, :#{new_column}"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,34 @@
1
+ module Ryakuzu
2
+ class CreateTableService
3
+ attr_reader :table, :column, :type
4
+
5
+ def initialize(table, column, type)
6
+ @table = table['name']
7
+ @column = column
8
+ @type = type
9
+ end
10
+
11
+ def call
12
+ invoke_migration
13
+ end
14
+
15
+ private
16
+
17
+ def invoke_migration
18
+ return if column.blank? || type.blank? || table.blank?
19
+ res = column.zip(type)
20
+ hash = Hash[*res.flatten]
21
+ string = make_string(hash)
22
+ text = "rails g model #{table.classify} #{string} && rake db:migrate"
23
+ system text
24
+ end
25
+
26
+ def make_string(hash)
27
+ str = ''
28
+ hash.each do |key, value|
29
+ str += key + ':' + value.downcase + ' ' if value
30
+ end
31
+ str
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,29 @@
1
+ module Ryakuzu
2
+ class MigrationService
3
+ attr_accessor :columns, :table, :old_table
4
+
5
+ def initialize(params = {})
6
+ @columns = params['column']
7
+ @table = params['name']
8
+ @old_table = params['old_name']
9
+ end
10
+
11
+ def call
12
+ run_table_migration(old_table, table) if table != old_table
13
+
14
+ columns.each_slice(2) do |k, v|
15
+ run_column_migration(v[1], k[1], table) if k[1] != v[1]
16
+ end
17
+ end
18
+
19
+ private
20
+
21
+ def run_table_migration(old_table, new_table)
22
+ Ryakuzu::TableService.new(old_table, new_table).call
23
+ end
24
+
25
+ def run_column_migration(old_name, new_name, table)
26
+ Ryakuzu::ColumnService.new(old_name, new_name, table).call
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,26 @@
1
+ module Ryakuzu
2
+ class RemoveService
3
+ attr_reader :table, :column
4
+
5
+ def initialize(**options)
6
+ @table = options[:table]
7
+ @column = options[:column]
8
+ end
9
+
10
+ def call
11
+ column.blank? ? run_drop_table_migration : run_remove_column_migration
12
+ end
13
+
14
+ private
15
+
16
+ def run_remove_column_migration
17
+ text = "remove_column :#{table}, :#{column}"
18
+ Ryakuzu::RunMigration.new(old_table: table, old_column: column).call(column, text, 'column')
19
+ end
20
+
21
+ def run_drop_table_migration
22
+ text = "drop_table :#{table}"
23
+ Ryakuzu::RunMigration.new(old_table: table).call(table, text, 'table')
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,43 @@
1
+ module Ryakuzu
2
+ class RunMigration
3
+ attr_accessor :old_table, :new_table, :old_column, :new_column
4
+ require 'fileutils'
5
+
6
+ def initialize(options = {})
7
+ @old_table = options[:old_table]
8
+ @new_table = options[:new_table]
9
+ @old_column = options[:old_column]
10
+ @new_column = options[:new_column]
11
+ end
12
+
13
+ def call(migration, text_line, type)
14
+ date = DateTime.now.to_s(:number)
15
+ class_name = migration.classify
16
+ migrate_name = "#{date}_change_#{type}_#{class_name.underscore}.rb"
17
+ text = text_migration(type, class_name, text_line)
18
+
19
+ migration(migrate_name, text, class_name)
20
+ end
21
+
22
+ def text_migration(type, class_name, text_line)
23
+ "class Change#{type.titleize}#{class_name} < ActiveRecord::Migration
24
+ def change
25
+ #{text_line}
26
+ end
27
+ end"
28
+ end
29
+
30
+ private
31
+
32
+ def migration(migrate, text_migration, klass)
33
+ output = File.new("./db/migrate/#{migrate}", 'a+')
34
+ output << text_migration
35
+ output.close
36
+ result = system 'rake db:migrate'
37
+ File.delete(output)
38
+ fail StandardError if result == false
39
+ rescue StandardError
40
+ "Cannot drop table, maybe it has reference to other tables? Find #{klass.singularize.downcase}_id in other tables and remove it."
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ module Ryakuzu
2
+ class TableService
3
+ attr_accessor :old_table, :new_table
4
+
5
+ def initialize(old_table, new_table)
6
+ @old_table = old_table
7
+ @new_table = new_table
8
+ end
9
+
10
+ def call
11
+ text = text_migration
12
+ Ryakuzu::RunMigration.new(old_table: old_table, new_table: new_table.tableize).call(new_table.tableize, text, 'table')
13
+ end
14
+
15
+ def text_migration
16
+ "rename_table :#{old_table}, :#{new_table.tableize}"
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/css/materialize.min.css">
2
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
3
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.97.3/js/materialize.min.js"></script>
@@ -0,0 +1,13 @@
1
+ .container
2
+ .row
3
+ hr
4
+ .col-md-1
5
+ = image_tag 'https://d13yacurqjgara.cloudfront.net/users/2156/screenshots/988487/slice_1_1x.png', class: 'img-responsive logo'
6
+ .col-md-3
7
+ h4.text-success#text-logo Ryakuzu - schema.rb interface
8
+ .col-md-2
9
+ = link_to 'Create Table', :add_table, method: :post, remote: true, class: 'btn btn-md btn-info waves-effect waves-light btn', data: { toggle: 'modal', target: "#tablemodal" } if schema_present?
10
+ .col-md-3
11
+ = link_to 'Save schema to CSV', :save_csv, method: :post, class: 'btn btn-primary waves-effect waves-light btn' if schema_present?
12
+ .col-md-2
13
+ iframe frameborder="0" height="30px" scrolling="0" src="https://ghbtns.com/github-btn.html?user=ID25&repo=ryakuzu&type=star&count=true&size=large" width="160px"
@@ -0,0 +1,30 @@
1
+ #loading
2
+ .preloader-wrapper.big.active
3
+ .spinner-layer.spinner-blue
4
+ .circle-clipper.left
5
+ .circle
6
+ .gap-patch
7
+ .circle
8
+ .circle-clipper.right
9
+ .circle
10
+ .spinner-layer.spinner-red
11
+ .circle-clipper.left
12
+ .circle
13
+ .gap-patch
14
+ .circle
15
+ .circle-clipper.right
16
+ .circle
17
+ .spinner-layer.spinner-yellow
18
+ .circle-clipper.left
19
+ .circle
20
+ .gap-patch
21
+ .circle
22
+ .circle-clipper.right
23
+ .circle
24
+ .spinner-layer.spinner-green
25
+ .circle-clipper.left
26
+ .circle
27
+ .gap-patch
28
+ .circle
29
+ .circle-clipper.right
30
+ .circle