rails_db 0.5.1 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/stylesheets/rails_db/app.css.scss +1 -1
- data/app/assets/stylesheets/rails_db/application.css +1 -0
- data/app/assets/stylesheets/rails_db/table.css.scss +7 -0
- data/app/controllers/rails_db/application_controller.rb +2 -0
- data/app/controllers/rails_db/tables_controller.rb +23 -4
- data/app/helpers/rails_db/application_helper.rb +4 -3
- data/app/helpers/rails_db/tables_helper.rb +14 -1
- data/app/views/rails_db/dashboard/index.html.erb +2 -1
- data/app/views/rails_db/tables/_data.html.erb +45 -11
- data/app/views/rails_db/tables/_show.html.erb +66 -2
- data/app/views/rails_db/tables/data.js.erb +2 -0
- data/app/views/rails_db/tables/destroy.js.erb +5 -0
- data/app/views/rails_db/tables/show.js.erb +3 -1
- data/config/routes.rb +6 -2
- data/lib/rails_db/adapters/base_adapter.rb +8 -0
- data/lib/rails_db/adapters/sqlite.rb +4 -0
- data/lib/rails_db/table.rb +16 -0
- data/lib/rails_db/table_pagination.rb +2 -1
- data/lib/rails_db/version.rb +1 -1
- data/test/dashboard_controller_test.rb +16 -2
- data/test/database_test.rb +2 -2
- data/test/dummy/app/models/legacy_account.rb +2 -0
- data/test/dummy/app/models/payment.rb +2 -0
- data/test/dummy/app/models/populate.rb +6 -1
- data/test/dummy/db/migrate/20151027192250_create_payments.rb +14 -0
- data/test/dummy/db/migrate/20151027223149_add_non_pk_table.rb +10 -0
- data/test/dummy/db/migrate/20151028191429_create_legacy_accounts.rb +7 -0
- data/test/dummy/db/rails_db.sqlite3 +0 -0
- data/test/dummy/db/rails_db_dev.sqlite3 +0 -0
- data/test/dummy/db/schema.rb +26 -1
- data/test/dummy/test/fixtures/legacy_accounts.yml +9 -0
- data/test/dummy/test/models/legacy_account_test.rb +7 -0
- data/test/sql_import_test.rb +2 -2
- data/test/table_test.rb +27 -2
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e21d3f6ad3581eb79a6953b41b34615c8de7c0d8
|
4
|
+
data.tar.gz: dd6c322be6728fb8d6fbf96b9c01803f0619b18f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0143d6f8a1247dc37d53bf657f8eb9e3d61836b61562d372d182b9b986cb4c8f74235895142549712a03a9a254523192f793b2b8a109e77d77de3a22b749d271
|
7
|
+
data.tar.gz: a268fde740ef44118e2d2ede9714ea682fd93049adedcd98891df223c1d6a4101834bc7dbc00f5056a15b280a141e30f05425cb5f7fe2b5b77d0ac5e6555872d
|
@@ -12,15 +12,34 @@ module RailsDb
|
|
12
12
|
def data
|
13
13
|
per_page = params[:per_page] || session[:per_page]
|
14
14
|
session[:per_page] = per_page
|
15
|
-
@table = RailsDb::Table.new(params[:table_id]).paginate :
|
16
|
-
:
|
17
|
-
:
|
18
|
-
:
|
15
|
+
@table = RailsDb::Table.new(params[:table_id]).paginate page: params[:page],
|
16
|
+
sort_column: params[:sort_column],
|
17
|
+
sort_order: params[:sort_order],
|
18
|
+
per_page: per_page
|
19
19
|
end
|
20
20
|
|
21
21
|
def csv
|
22
22
|
@table = RailsDb::Table.new(params[:table_id])
|
23
23
|
send_data(@table.to_csv, type: 'text/csv; charset=utf-8; header=present', filename: "#{@table.name}.csv")
|
24
24
|
end
|
25
|
+
|
26
|
+
def truncate
|
27
|
+
@table = RailsDb::Table.new(params[:table_id])
|
28
|
+
@table.truncate
|
29
|
+
render :data
|
30
|
+
end
|
31
|
+
|
32
|
+
def destroy
|
33
|
+
@table = RailsDb::Table.new(params[:table_id]).paginate page: params[:page],
|
34
|
+
sort_column: params[:sort_column],
|
35
|
+
sort_order: params[:sort_order],
|
36
|
+
per_page: session[:per_page]
|
37
|
+
@table.delete(params[:pk_id])
|
38
|
+
respond_to do |page|
|
39
|
+
page.html { redirect_to action: :data, table_id: params[:table_id] }
|
40
|
+
page.js {}
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
25
44
|
end
|
26
45
|
end
|
@@ -34,17 +34,18 @@ module RailsDb
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def paginate_table_entries(entries)
|
37
|
+
params.delete(:id)
|
37
38
|
return if entries.total_pages == 1
|
38
39
|
prev_page_text = "#{fa_icon('arrow-left')} Previous".html_safe
|
39
40
|
next_page_text = "Next #{fa_icon('arrow-right')}".html_safe
|
40
41
|
|
41
42
|
html = '<div class="pagination">'
|
42
43
|
if entries.previous_page
|
43
|
-
html << link_to(prev_page_text, params.merge({ page: entries.previous_page }), { remote: true, class: 'page' })
|
44
|
+
html << link_to(prev_page_text, params.merge({ action: :data, page: entries.previous_page }), { remote: true, class: 'page' })
|
44
45
|
end
|
45
46
|
html << "#{page_links_for_pagination(entries)}"
|
46
47
|
if entries.next_page
|
47
|
-
html << link_to(next_page_text, params.merge({ page: entries.next_page }), { remote: true, class: 'page' })
|
48
|
+
html << link_to(next_page_text, params.merge({ action: :data, page: entries.next_page }), { remote: true, class: 'page' })
|
48
49
|
end
|
49
50
|
html << '</div>'
|
50
51
|
|
@@ -61,7 +62,7 @@ module RailsDb
|
|
61
62
|
if page == entries.current_page
|
62
63
|
links << content_tag(:b, page, { class: 'page current' })
|
63
64
|
else
|
64
|
-
links << link_to(page, params.merge({ page: page}), { remote: true, class: 'page' })
|
65
|
+
links << link_to(page, params.merge({ action: :data, page: page}), { remote: true, class: 'page' })
|
65
66
|
end
|
66
67
|
links << ' ... ' if page != pages.last && (page + 1) != pages[index+1]
|
67
68
|
end
|
@@ -19,7 +19,7 @@ module RailsDb
|
|
19
19
|
title = titleize_column(column, title)
|
20
20
|
css_class = (column == params[:sort_column]) ? "current #{params[:sort_order]}" : nil
|
21
21
|
sort_order = (column == params[:sort_column] && params[:sort_order] == 'asc') ? 'desc' : 'asc'
|
22
|
-
link_to title, params.merge({ sort_column: column, sort_order: sort_order }), {remote: true, class: css_class }
|
22
|
+
link_to title, params.merge({ action: :data, sort_column: column, sort_order: sort_order }), {remote: true, class: css_class }
|
23
23
|
end
|
24
24
|
|
25
25
|
def titleize_column(column, title = nil)
|
@@ -30,5 +30,18 @@ module RailsDb
|
|
30
30
|
link_to raw("#{fa_icon('database')} SQL Query"), rails_db.sql_path(sql: "select * from #{table} limit 10")
|
31
31
|
end
|
32
32
|
|
33
|
+
def delete_row_path(table, record)
|
34
|
+
table_destroy_path(table,
|
35
|
+
pk_id: record[table.primary_key],
|
36
|
+
page: params[:page],
|
37
|
+
sort_column: params[:sort_column],
|
38
|
+
sort_order: params[:sort_order])
|
39
|
+
end
|
40
|
+
|
41
|
+
def table_pagination_path
|
42
|
+
params.delete(:pk_id)
|
43
|
+
params.merge({action: :data})
|
44
|
+
end
|
45
|
+
|
33
46
|
end
|
34
47
|
end
|
@@ -6,7 +6,7 @@
|
|
6
6
|
<p>Welcome, in Rails DB you can do:</p>
|
7
7
|
|
8
8
|
<ul>
|
9
|
-
<li>view content of DB tables</li>
|
9
|
+
<li>view content and schema of DB tables (including indexes)</li>
|
10
10
|
<li>sort content of DB tables</li>
|
11
11
|
<li>execute SQL queries</li>
|
12
12
|
<li>autocomplete for your SQL queries</li>
|
@@ -21,6 +21,7 @@
|
|
21
21
|
<li>white/black lists</li>
|
22
22
|
<li>data-tables inside your app</li>
|
23
23
|
<li>ajax-ify Rails DB</li>
|
24
|
+
<li>delete records, truncate tables</li>
|
24
25
|
<li>visualize SQL schema (future)</li>
|
25
26
|
<li>CRUD for table records (future)</li>
|
26
27
|
</ul>
|
@@ -12,29 +12,61 @@
|
|
12
12
|
<dd><%= link_to raw("#{fa_icon('tasks')} Schema"), table_path(@table), remote: true %></dd>
|
13
13
|
<dd><%= select_top_from_table(@table.name) %></dd>
|
14
14
|
<dd><%= link_to raw("#{fa_icon('file-excel-o')} Export"), table_csv_path(@table) %></dd>
|
15
|
+
<dd>
|
16
|
+
<a href="#" data-options="align: bottom" data-dropdown="drop"><%= fa_icon 'th-large' %> Functions</a>
|
17
|
+
</dd>
|
15
18
|
</dl>
|
16
19
|
|
20
|
+
<ul id="drop" class="f-dropdown" data-dropdown-content>
|
21
|
+
<li><%= link_to raw("#{fa_icon('trash-o')} Truncate Table"), table_truncate_path(@table), remote: true, confirm: 'Are you sure?', data: {confirm: 'Are you sure?'} %></a></li>
|
22
|
+
</ul>
|
23
|
+
|
17
24
|
<div class='scrollable'>
|
18
25
|
<table>
|
26
|
+
|
19
27
|
<thead>
|
20
28
|
<tr>
|
29
|
+
<% if @table.primary_key.present? %>
|
30
|
+
<th class='delete_td'></th>
|
31
|
+
<% end %>
|
21
32
|
<% @table.columns.each do |column| %>
|
22
|
-
<th
|
33
|
+
<th>
|
34
|
+
<%= sortable column.name %>
|
35
|
+
</th>
|
23
36
|
<% end %>
|
24
37
|
</tr>
|
25
38
|
</thead>
|
39
|
+
|
26
40
|
<% n = 0 %>
|
41
|
+
|
27
42
|
<tbody>
|
28
43
|
<% @table.data.each do |record| %>
|
29
44
|
<tr>
|
45
|
+
<% if @table.primary_key.present? %>
|
46
|
+
<td>
|
47
|
+
<%= link_to fa_icon('minus-circle'), delete_row_path(@table, record), remote: true, title: 'Delete Record', confirm: 'Are you sure you want to delete this record?', data: {confirm: 'Are you sure you want to delete this record?'} %>
|
48
|
+
</td>
|
49
|
+
<% end %>
|
50
|
+
|
30
51
|
<% @table.columns.each do |column| %>
|
31
|
-
|
32
|
-
|
52
|
+
<td>
|
53
|
+
<% name = column.name %>
|
54
|
+
<%= format_value(column, record[name]) %>
|
55
|
+
</td>
|
33
56
|
<% end %>
|
34
57
|
</tr>
|
35
58
|
<% end %>
|
36
59
|
<% n += 1 %>
|
60
|
+
<% if @table.data.total_entries == 0 %>
|
61
|
+
<tr>
|
62
|
+
<% if @table.primary_key.present? %>
|
63
|
+
<td></td>
|
64
|
+
<% end %>
|
65
|
+
<td>No Records</td>
|
66
|
+
</tr>
|
67
|
+
<% end %>
|
37
68
|
</tbody>
|
69
|
+
|
38
70
|
<% if n > 10 %>
|
39
71
|
<tfoot>
|
40
72
|
<tr>
|
@@ -52,15 +84,17 @@
|
|
52
84
|
<span class="radius info label">Time: <%= @table.data.time %> seconds</span>
|
53
85
|
</p>
|
54
86
|
|
55
|
-
|
56
|
-
|
57
|
-
<%=
|
58
|
-
|
59
|
-
|
87
|
+
<% if @table.data.total_entries > 0 %>
|
88
|
+
<div class='left'>
|
89
|
+
<%= form_tag table_pagination_path, method: :get, remote: true do %>
|
90
|
+
<%= select_tag :per_page, options_for_select([10, 15, 20, 50, 100, 200, 500], @table.data.per_page), class: 'per_page_pagination_select' %>
|
91
|
+
<% end %>
|
92
|
+
</div>
|
60
93
|
|
61
|
-
<div class='left per_page_pagination'>
|
62
|
-
|
63
|
-
</div>
|
94
|
+
<div class='left per_page_pagination'>
|
95
|
+
<%= paginate_table_entries @table.data %>
|
96
|
+
</div>
|
97
|
+
<% end %>
|
64
98
|
|
65
99
|
<div class='clear'></div>
|
66
100
|
|
@@ -10,11 +10,23 @@
|
|
10
10
|
<dd class="active"><%= link_to raw("#{fa_icon('tasks')} Schema"), table_path(@table), remote: true %></dd>
|
11
11
|
<dd><%= select_top_from_table(@table.name) %></dd>
|
12
12
|
<dd><%= link_to raw("#{fa_icon('file-excel-o')} Export"), table_csv_path(@table) %></dd>
|
13
|
+
<dd>
|
14
|
+
<a href="#" data-options="align: bottom" data-dropdown="drop"><%= fa_icon 'th-large' %> Functions</a>
|
15
|
+
</dd>
|
13
16
|
</dl>
|
14
17
|
|
18
|
+
<ul id="drop" class="f-dropdown" data-dropdown-content>
|
19
|
+
<li><%= link_to raw("#{fa_icon('trash-o')} Truncate Table"), table_truncate_path(@table), remote: true, confirm: 'Are you sure?', data: {confirm: 'Are you sure?'} %></a></li>
|
20
|
+
</ul>
|
21
|
+
|
22
|
+
<h3>Schema</h3>
|
23
|
+
|
15
24
|
<table>
|
16
25
|
<thead>
|
17
26
|
<tr>
|
27
|
+
<% if @table.primary_key.present? %>
|
28
|
+
<th>PK</th>
|
29
|
+
<% end %>
|
18
30
|
<% @table.column_properties.each do |key| %>
|
19
31
|
<th><%= key.titleize.upcase %></th>
|
20
32
|
<% end %>
|
@@ -23,10 +35,62 @@
|
|
23
35
|
<tbody>
|
24
36
|
<% @table.columns.each do |col| %>
|
25
37
|
<tr>
|
38
|
+
<% if @table.primary_key %>
|
39
|
+
<% if @table.primary_key == col.name %>
|
40
|
+
<td>
|
41
|
+
<span class='pk'><%= fa_icon 'key' %></span>
|
42
|
+
</td>
|
43
|
+
<% else %>
|
44
|
+
<td></td>
|
45
|
+
<% end %>
|
46
|
+
<% end %>
|
47
|
+
|
26
48
|
<% @table.column_properties.each do |key| %>
|
27
|
-
<td class="<%= key %>"
|
49
|
+
<td class="<%= key %>">
|
50
|
+
<% value = col.send(key) %>
|
51
|
+
<%= value %>
|
52
|
+
</td>
|
28
53
|
<% end %>
|
29
54
|
</tr>
|
30
55
|
<% end %>
|
31
56
|
</tbody>
|
32
|
-
</table>
|
57
|
+
</table>
|
58
|
+
|
59
|
+
|
60
|
+
<h3>Indexes</h3>
|
61
|
+
|
62
|
+
<table>
|
63
|
+
<thead>
|
64
|
+
<tr>
|
65
|
+
<th>Name</th>
|
66
|
+
<th>Unique</th>
|
67
|
+
<th>Columns</th>
|
68
|
+
<th>Length</th>
|
69
|
+
<th>Orders</th>
|
70
|
+
<% if Rails::VERSION::MAJOR >= 4 %>
|
71
|
+
<th>Where</th>
|
72
|
+
<th>Type</th>
|
73
|
+
<th>Using</th>
|
74
|
+
<% end %>
|
75
|
+
</tr>
|
76
|
+
</thead>
|
77
|
+
<tbody>
|
78
|
+
<% @table.indexes.each do |index| %>
|
79
|
+
<tr>
|
80
|
+
<td><%= index.name %></td>
|
81
|
+
<td><%= index.unique %></td>
|
82
|
+
<td><%= index.columns %></td>
|
83
|
+
<td><%= index.lengths %></td>
|
84
|
+
<td><%= index.orders %></td>
|
85
|
+
<% if Rails::VERSION::MAJOR >= 4 %>
|
86
|
+
<td><%= index.where %></td>
|
87
|
+
<td><%= index.type %></td>
|
88
|
+
<td><%= index.using %></td>
|
89
|
+
<% end %>
|
90
|
+
</tr>
|
91
|
+
<% end %>
|
92
|
+
<% if @table.indexes.none? %>
|
93
|
+
<tr><td colspan='7'>No Indexes</td></tr>
|
94
|
+
<% end %>
|
95
|
+
</tbody>
|
96
|
+
</table>
|
data/config/routes.rb
CHANGED
@@ -1,19 +1,23 @@
|
|
1
1
|
RailsDb::Engine.routes.draw do
|
2
2
|
root :to => 'dashboard#index'
|
3
|
+
|
3
4
|
resources :tables, :only => [:index, :show] do
|
4
5
|
get 'data'
|
5
6
|
get 'csv'
|
7
|
+
get 'truncate'
|
8
|
+
get 'destroy' # to handle opens in new window (GET)
|
6
9
|
end
|
10
|
+
|
7
11
|
get '/sql' => 'sql#index', as: :sql
|
12
|
+
get '/import' => 'sql#import', as: :sql_import
|
8
13
|
post '/execute' => 'sql#execute', as: :sql_execute
|
9
14
|
post '/sql-csv' => 'sql#csv', as: :sql_csv
|
10
|
-
|
11
|
-
get '/import' => 'sql#import', as: :sql_import
|
12
15
|
post '/import-start' => 'sql#import_start', as: :sql_start_import
|
13
16
|
|
14
17
|
get '/data-table' => 'dashboard#data_table', as: :data_table
|
15
18
|
end
|
16
19
|
|
20
|
+
|
17
21
|
if RailsDb.automatic_routes_mount
|
18
22
|
Rails.application.routes.draw do
|
19
23
|
mount_rails_db_routes
|
@@ -28,6 +28,14 @@ module RailsDb
|
|
28
28
|
'text/x-sql'
|
29
29
|
end
|
30
30
|
|
31
|
+
def self.truncate(table_name)
|
32
|
+
execute("TRUNCATE TABLE #{table_name};")
|
33
|
+
end
|
34
|
+
|
35
|
+
def self.delete(table_name, pk_name, pk_id)
|
36
|
+
execute("DELETE FROM #{table_name} WHERE #{pk_name} = #{pk_id};")
|
37
|
+
end
|
38
|
+
|
31
39
|
private
|
32
40
|
|
33
41
|
def self.multiple_execute(sql, divider = ";\n")
|
data/lib/rails_db/table.rb
CHANGED
@@ -29,6 +29,22 @@ module RailsDb
|
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
|
+
def indexes
|
33
|
+
connection.indexes(name)
|
34
|
+
end
|
35
|
+
|
36
|
+
def truncate
|
37
|
+
RailsDb::Database.adapter.truncate(name)
|
38
|
+
end
|
39
|
+
|
40
|
+
def primary_key
|
41
|
+
connection.primary_key(name)
|
42
|
+
end
|
43
|
+
|
44
|
+
def delete(id)
|
45
|
+
RailsDb::Database.adapter.delete(name, primary_key, id)
|
46
|
+
end
|
47
|
+
|
32
48
|
end # module
|
33
49
|
|
34
50
|
end
|
@@ -1,12 +1,13 @@
|
|
1
1
|
module RailsDb
|
2
2
|
module TablePagination
|
3
|
+
DEFAULT_PAGINATION_PER_PAGE = 10
|
3
4
|
|
4
5
|
def next_page
|
5
6
|
current_page < total_pages ? (current_page + 1) : nil
|
6
7
|
end
|
7
8
|
|
8
9
|
def paginate(options = {})
|
9
|
-
self.per_page = (options[:per_page] ||
|
10
|
+
self.per_page = (options[:per_page] || DEFAULT_PAGINATION_PER_PAGE).to_i
|
10
11
|
self.current_page = (options[:page] || 1).to_i
|
11
12
|
self.offset = current_page * per_page - per_page
|
12
13
|
self.sort_column = options[:sort_column]
|
data/lib/rails_db/version.rb
CHANGED
@@ -3,8 +3,11 @@ require 'test_helper'
|
|
3
3
|
class DashboardControllerTest < ActionDispatch::IntegrationTest
|
4
4
|
|
5
5
|
test "should get index" do
|
6
|
-
User.
|
7
|
-
Account.
|
6
|
+
User.delete_all
|
7
|
+
Account.delete_all
|
8
|
+
|
9
|
+
user = User.create(name: 'Igor')
|
10
|
+
account = Account.create(name: 'Igor')
|
8
11
|
|
9
12
|
get '/rails/db'
|
10
13
|
assert_equal 200, status
|
@@ -31,6 +34,17 @@ class DashboardControllerTest < ActionDispatch::IntegrationTest
|
|
31
34
|
|
32
35
|
get '/'
|
33
36
|
assert_equal 200, status
|
37
|
+
|
38
|
+
get '/rails/db/tables/users/data?sort_column=id&sort_order=desc'
|
39
|
+
assert_equal 200, status
|
40
|
+
|
41
|
+
assert_equal 1, User.count
|
42
|
+
get "/rails/db/tables/users/destroy?pk_id=#{user.id}"
|
43
|
+
assert_equal 302, status
|
44
|
+
assert_equal 0, User.count
|
45
|
+
|
46
|
+
get '/rails/db/tables/accounts/csv'
|
47
|
+
assert_equal 200, status
|
34
48
|
end
|
35
49
|
|
36
50
|
end
|
data/test/database_test.rb
CHANGED
@@ -6,11 +6,11 @@ class DatabaseTest < ActiveSupport::TestCase
|
|
6
6
|
end
|
7
7
|
|
8
8
|
test "tables" do
|
9
|
-
assert_equal RailsDb::Database.tables, ["accounts", "comments", "contacts", "projects", "users"]
|
9
|
+
assert_equal RailsDb::Database.tables, ["accounts", "comments", "contacts", "legacy_accounts", "payments", "projects", "projects_users", "users"]
|
10
10
|
end
|
11
11
|
|
12
12
|
test "accessible tables" do
|
13
|
-
assert_equal RailsDb::Database.accessible_tables, ["accounts", "comments", "contacts", "projects", "users"]
|
13
|
+
assert_equal RailsDb::Database.accessible_tables, ["accounts", "comments", "contacts", "legacy_accounts", "payments", "projects", "projects_users", "users"]
|
14
14
|
end
|
15
15
|
|
16
16
|
test 'adapter' do
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Populate
|
2
2
|
|
3
|
-
def
|
3
|
+
def Populate.populate
|
4
4
|
require 'populator'
|
5
5
|
require 'faker'
|
6
6
|
|
@@ -32,6 +32,11 @@ class Populate
|
|
32
32
|
Project.populate 100 do |project|
|
33
33
|
project.name = Faker::Company.name
|
34
34
|
end
|
35
|
+
|
36
|
+
LegacyAccount.populate 100 do |account|
|
37
|
+
account.uuid = rand(1_000_000)
|
38
|
+
account.name = Faker::Company.name
|
39
|
+
end
|
35
40
|
end
|
36
41
|
|
37
42
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
class CreatePayments < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :payments do |t|
|
4
|
+
t.decimal :amount
|
5
|
+
t.integer :project_id
|
6
|
+
|
7
|
+
t.timestamps null: false
|
8
|
+
end
|
9
|
+
add_index :payments, :project_id
|
10
|
+
add_index :contacts, [:name, :email]
|
11
|
+
add_index :users, [:name]
|
12
|
+
add_index :users, [:salary]
|
13
|
+
end
|
14
|
+
end
|
Binary file
|
Binary file
|
data/test/dummy/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended that you check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(version:
|
14
|
+
ActiveRecord::Schema.define(version: 20151028191429) do
|
15
15
|
|
16
16
|
create_table "accounts", force: :cascade do |t|
|
17
17
|
t.string "name"
|
@@ -35,6 +35,21 @@ ActiveRecord::Schema.define(version: 20151015145740) do
|
|
35
35
|
t.datetime "updated_at", null: false
|
36
36
|
end
|
37
37
|
|
38
|
+
add_index "contacts", ["name", "email"], name: "index_contacts_on_name_and_email"
|
39
|
+
|
40
|
+
create_table "legacy_accounts", primary_key: "uuid", force: :cascade do |t|
|
41
|
+
t.string "name"
|
42
|
+
end
|
43
|
+
|
44
|
+
create_table "payments", force: :cascade do |t|
|
45
|
+
t.decimal "amount"
|
46
|
+
t.integer "project_id"
|
47
|
+
t.datetime "created_at", null: false
|
48
|
+
t.datetime "updated_at", null: false
|
49
|
+
end
|
50
|
+
|
51
|
+
add_index "payments", ["project_id"], name: "index_payments_on_project_id"
|
52
|
+
|
38
53
|
create_table "projects", force: :cascade do |t|
|
39
54
|
t.string "name"
|
40
55
|
t.string "description_880941"
|
@@ -81,6 +96,14 @@ ActiveRecord::Schema.define(version: 20151015145740) do
|
|
81
96
|
t.datetime "updated_at", null: false
|
82
97
|
end
|
83
98
|
|
99
|
+
create_table "projects_users", id: false, force: :cascade do |t|
|
100
|
+
t.integer "project_id"
|
101
|
+
t.integer "user_id"
|
102
|
+
end
|
103
|
+
|
104
|
+
add_index "projects_users", ["project_id"], name: "index_projects_users_on_project_id"
|
105
|
+
add_index "projects_users", ["user_id"], name: "index_projects_users_on_user_id"
|
106
|
+
|
84
107
|
create_table "users", force: :cascade do |t|
|
85
108
|
t.string "name"
|
86
109
|
t.integer "age"
|
@@ -93,5 +116,7 @@ ActiveRecord::Schema.define(version: 20151015145740) do
|
|
93
116
|
end
|
94
117
|
|
95
118
|
add_index "users", ["account_id"], name: "index_users_on_account_id"
|
119
|
+
add_index "users", ["name"], name: "index_users_on_name"
|
120
|
+
add_index "users", ["salary"], name: "index_users_on_salary"
|
96
121
|
|
97
122
|
end
|
data/test/sql_import_test.rb
CHANGED
@@ -7,12 +7,12 @@ class SqlImportTest < ActiveSupport::TestCase
|
|
7
7
|
end
|
8
8
|
|
9
9
|
test "import" do
|
10
|
-
assert_equal RailsDb::Database.tables, ["accounts", "comments", "contacts", "projects", "users"]
|
10
|
+
assert_equal RailsDb::Database.tables, ["accounts", "comments", "contacts", "legacy_accounts", "payments", "projects", "projects_users", "users"]
|
11
11
|
file = File.open("#{Rails.root}/../test_sql_#{RailsDb::Database.adapter.adapter_name}.sql")
|
12
12
|
importer = RailsDb::SqlImport.new(file)
|
13
13
|
importer.import
|
14
14
|
assert importer.result.ok?, "Import successfull?"
|
15
|
-
assert_equal RailsDb::Database.tables, ["accounts", "comments", "contacts", "projects", 't', "users"]
|
15
|
+
assert_equal RailsDb::Database.tables, ["accounts", "comments", "contacts", "legacy_accounts", "payments", "projects", "projects_users", 't', "users"]
|
16
16
|
end
|
17
17
|
|
18
18
|
end
|
data/test/table_test.rb
CHANGED
@@ -12,8 +12,33 @@ class TableTest < ActiveSupport::TestCase
|
|
12
12
|
end
|
13
13
|
|
14
14
|
test 'to_csv' do
|
15
|
-
User.create(name:
|
16
|
-
assert_not_equal @users_table.to_csv,
|
15
|
+
User.create(name: 'igor')
|
16
|
+
assert_not_equal @users_table.to_csv, ''
|
17
|
+
end
|
18
|
+
|
19
|
+
test 'truncate' do
|
20
|
+
User.delete_all
|
21
|
+
User.create(name: 'igor')
|
22
|
+
assert_equal 1, User.count
|
23
|
+
@users_table.truncate
|
24
|
+
assert_equal 0, User.count
|
25
|
+
end
|
26
|
+
|
27
|
+
test 'primary_key' do
|
28
|
+
assert_equal 'id', @users_table.primary_key
|
29
|
+
projects_users_table = RailsDb::Table.new('projects_users')
|
30
|
+
assert_nil projects_users_table.primary_key
|
31
|
+
end
|
32
|
+
|
33
|
+
test 'delete' do
|
34
|
+
User.delete_all
|
35
|
+
user_1 = User.create(name: 'igor')
|
36
|
+
user_2 = User.create(name: 'john')
|
37
|
+
assert_equal 2, User.count
|
38
|
+
@users_table.delete(user_1.id)
|
39
|
+
assert_equal 1, User.count
|
40
|
+
assert_equal 0, User.where(name: 'igor').count
|
41
|
+
assert_equal 1, User.where(name: 'john').count
|
17
42
|
end
|
18
43
|
|
19
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails_db
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.6'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Igor Kasyanchuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -216,6 +216,7 @@ files:
|
|
216
216
|
- app/assets/stylesheets/rails_db/foundation_and_overrides.css.scss
|
217
217
|
- app/assets/stylesheets/rails_db/pagination.css.scss
|
218
218
|
- app/assets/stylesheets/rails_db/sidebar.css.scss
|
219
|
+
- app/assets/stylesheets/rails_db/table.css.scss
|
219
220
|
- app/controllers/rails_db/application_controller.rb
|
220
221
|
- app/controllers/rails_db/dashboard_controller.rb
|
221
222
|
- app/controllers/rails_db/sql_controller.rb
|
@@ -244,6 +245,7 @@ files:
|
|
244
245
|
- app/views/rails_db/tables/_show.html.erb
|
245
246
|
- app/views/rails_db/tables/data.html.erb
|
246
247
|
- app/views/rails_db/tables/data.js.erb
|
248
|
+
- app/views/rails_db/tables/destroy.js.erb
|
247
249
|
- app/views/rails_db/tables/index.html.erb
|
248
250
|
- app/views/rails_db/tables/show.html.erb
|
249
251
|
- app/views/rails_db/tables/show.js.erb
|
@@ -292,6 +294,8 @@ files:
|
|
292
294
|
- test/dummy/app/models/account.rb
|
293
295
|
- test/dummy/app/models/comment.rb
|
294
296
|
- test/dummy/app/models/contact.rb
|
297
|
+
- test/dummy/app/models/legacy_account.rb
|
298
|
+
- test/dummy/app/models/payment.rb
|
295
299
|
- test/dummy/app/models/populate.rb
|
296
300
|
- test/dummy/app/models/project.rb
|
297
301
|
- test/dummy/app/models/user.rb
|
@@ -331,6 +335,9 @@ files:
|
|
331
335
|
- test/dummy/db/migrate/20151014183823_create_projects.rb
|
332
336
|
- test/dummy/db/migrate/20151014184243_add_long_text.rb
|
333
337
|
- test/dummy/db/migrate/20151015145740_populate_db.rb
|
338
|
+
- test/dummy/db/migrate/20151027192250_create_payments.rb
|
339
|
+
- test/dummy/db/migrate/20151027223149_add_non_pk_table.rb
|
340
|
+
- test/dummy/db/migrate/20151028191429_create_legacy_accounts.rb
|
334
341
|
- test/dummy/db/rails_db.sqlite3
|
335
342
|
- test/dummy/db/rails_db_dev.sqlite3
|
336
343
|
- test/dummy/db/schema.rb
|
@@ -342,11 +349,13 @@ files:
|
|
342
349
|
- test/dummy/test/fixtures/accounts.yml
|
343
350
|
- test/dummy/test/fixtures/comments.yml
|
344
351
|
- test/dummy/test/fixtures/contacts.yml
|
352
|
+
- test/dummy/test/fixtures/legacy_accounts.yml
|
345
353
|
- test/dummy/test/fixtures/projects.yml
|
346
354
|
- test/dummy/test/fixtures/users.yml
|
347
355
|
- test/dummy/test/models/account_test.rb
|
348
356
|
- test/dummy/test/models/comment_test.rb
|
349
357
|
- test/dummy/test/models/contact_test.rb
|
358
|
+
- test/dummy/test/models/legacy_account_test.rb
|
350
359
|
- test/dummy/test/models/project_test.rb
|
351
360
|
- test/dummy/test/models/user_test.rb
|
352
361
|
- test/rails_db_data_table_helper_test.rb
|
@@ -401,6 +410,8 @@ test_files:
|
|
401
410
|
- test/dummy/app/models/account.rb
|
402
411
|
- test/dummy/app/models/comment.rb
|
403
412
|
- test/dummy/app/models/contact.rb
|
413
|
+
- test/dummy/app/models/legacy_account.rb
|
414
|
+
- test/dummy/app/models/payment.rb
|
404
415
|
- test/dummy/app/models/populate.rb
|
405
416
|
- test/dummy/app/models/project.rb
|
406
417
|
- test/dummy/app/models/user.rb
|
@@ -440,6 +451,9 @@ test_files:
|
|
440
451
|
- test/dummy/db/migrate/20151014183823_create_projects.rb
|
441
452
|
- test/dummy/db/migrate/20151014184243_add_long_text.rb
|
442
453
|
- test/dummy/db/migrate/20151015145740_populate_db.rb
|
454
|
+
- test/dummy/db/migrate/20151027192250_create_payments.rb
|
455
|
+
- test/dummy/db/migrate/20151027223149_add_non_pk_table.rb
|
456
|
+
- test/dummy/db/migrate/20151028191429_create_legacy_accounts.rb
|
443
457
|
- test/dummy/db/rails_db.sqlite3
|
444
458
|
- test/dummy/db/rails_db_dev.sqlite3
|
445
459
|
- test/dummy/db/schema.rb
|
@@ -453,11 +467,13 @@ test_files:
|
|
453
467
|
- test/dummy/test/fixtures/accounts.yml
|
454
468
|
- test/dummy/test/fixtures/comments.yml
|
455
469
|
- test/dummy/test/fixtures/contacts.yml
|
470
|
+
- test/dummy/test/fixtures/legacy_accounts.yml
|
456
471
|
- test/dummy/test/fixtures/projects.yml
|
457
472
|
- test/dummy/test/fixtures/users.yml
|
458
473
|
- test/dummy/test/models/account_test.rb
|
459
474
|
- test/dummy/test/models/comment_test.rb
|
460
475
|
- test/dummy/test/models/contact_test.rb
|
476
|
+
- test/dummy/test/models/legacy_account_test.rb
|
461
477
|
- test/dummy/test/models/project_test.rb
|
462
478
|
- test/dummy/test/models/user_test.rb
|
463
479
|
- test/rails_db_data_table_helper_test.rb
|