backlog 0.36.2 → 0.37.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +16 -4
- data/Gemfile.lock +130 -0
- data/History.txt +17 -0
- data/README.txt +0 -2
- data/Rakefile +17 -7
- data/app/controllers/absences_controller.rb +1 -2
- data/app/controllers/application_controller.rb +13 -14
- data/app/controllers/application_controller.rb.rails2 +186 -0
- data/app/controllers/estimates_controller.rb +1 -1
- data/app/controllers/groups_controller.rb +3 -1
- data/app/controllers/periods_controller.rb +61 -50
- data/app/controllers/{backlogs_controller.rb → projects_controller.rb} +35 -35
- data/app/controllers/search_controller.rb +2 -2
- data/app/controllers/tasks_controller.rb +11 -11
- data/app/controllers/user_controller.rb +6 -4
- data/app/controllers/welcome_controller.rb +4 -4
- data/app/controllers/work_locks_controller.rb +2 -2
- data/app/controllers/works_controller.rb +31 -31
- data/app/helpers/application_helper.rb +2 -2
- data/app/helpers/application_helper.rb.rails2 +118 -0
- data/app/helpers/periods_helper.rb +3 -3
- data/app/helpers/{backlogs_helper.rb → projects_helper.rb} +5 -5
- data/app/helpers/user_helper.rb +2 -2
- data/app/{models → mailers}/user_notify.rb +1 -0
- data/app/models/absence.rb +2 -2
- data/{lib → app/models}/clock.rb +0 -0
- data/app/models/estimate.rb +2 -2
- data/app/models/party.rb +1 -2
- data/app/models/period.rb +17 -18
- data/app/models/{backlog.rb → project.rb} +2 -2
- data/app/models/sidebar.rb +2 -2
- data/app/models/task.rb +28 -28
- data/app/models/user.rb +5 -4
- data/app/models/work.rb +29 -23
- data/app/models/work_lock_nagger.rb +1 -1
- data/app/models/works_report_filter.rb +4 -4
- data/app/views/customers/_name_list.rhtml +1 -1
- data/app/views/layouts/_headers.rhtml +2 -1
- data/app/views/layouts/_left_top.rhtml +32 -29
- data/app/views/layouts/_shortcuts.rhtml +15 -9
- data/app/views/layouts/_shortcuts_js.rhtml +4 -4
- data/app/views/layouts/mwrt002.html.erb +44 -0
- data/app/views/periods/_burn_down_chart.rhtml +1 -1
- data/app/views/periods/_show_active.rhtml +3 -3
- data/app/views/periods/_title.rhtml +1 -1
- data/app/views/{backlogs → projects}/_buttons.rhtml +4 -4
- data/app/views/projects/_form.rhtml +44 -0
- data/app/views/projects/_name_list.rhtml +5 -0
- data/app/views/projects/edit.rhtml +14 -0
- data/app/views/{backlogs → projects}/finish_task.rjs +0 -0
- data/app/views/projects/list.rhtml +16 -0
- data/app/views/{backlogs → projects}/move_task_to_period.rjs +0 -0
- data/app/views/{backlogs → projects}/new.rhtml +1 -1
- data/app/views/{backlogs → projects}/reopen_task.rjs +0 -0
- data/app/views/{backlogs → projects}/show.rhtml +6 -6
- data/app/views/search/results.rhtml +3 -3
- data/app/views/tasks/_backlog_header.rhtml +4 -4
- data/app/views/tasks/_completed.rhtml +2 -2
- data/app/views/tasks/_form.rhtml +13 -13
- data/app/views/tasks/_task.rhtml +10 -10
- data/app/views/tasks/edit.rhtml +1 -1
- data/app/views/tasks/list.rhtml +3 -3
- data/app/views/tasks/list_started.rhtml +4 -4
- data/app/views/tasks/start_work.rjs +1 -1
- data/app/views/user/login.rhtml +1 -1
- data/app/views/user/signup.rhtml +1 -1
- data/app/views/user/welcome.rhtml +1 -1
- data/app/views/works/_description_list.rhtml +1 -1
- data/app/views/works/_form.rhtml +5 -5
- data/app/views/works/_new_row.rhtml +8 -8
- data/app/views/works/_row.rhtml +1 -1
- data/app/views/works/_task_id_list.rhtml +1 -1
- data/app/views/works/daily_work_sheet.rhtml +1 -1
- data/app/views/works/list.rhtml +5 -5
- data/app/views/works/list_excel.rhtml +2 -2
- data/app/views/works/timeliste.rhtml +14 -14
- data/app/views/works/weekly_work_sheet.rhtml +5 -5
- data/app/views/works/weekly_work_sheet_details.rhtml +5 -5
- data/backlog.gemspec +44 -0
- data/bin/backlog +5 -1
- data/config.ru +4 -0
- data/config/application.rb +10 -0
- data/config/boot.rb +12 -116
- data/config/database.yml +3 -6
- data/config/database.yml~ +17 -0
- data/config/environment.rb +28 -49
- data/config/environments/development.rb +24 -20
- data/config/environments/development.rb.rails2 +26 -0
- data/config/environments/production.rb +26 -22
- data/config/environments/test.rb +20 -15
- data/config/environments/user_environment.rb +1 -1
- data/config/initializers/backtrace_silencers.rb +7 -0
- data/config/initializers/inflections.rb +10 -0
- data/config/initializers/jdbc.rb +1 -1
- data/config/initializers/mime_types.rb +5 -0
- data/config/initializers/secret_token.rb +7 -0
- data/config/initializers/session_store.rb +8 -0
- data/config/locales/en.yml +22 -11
- data/config/locales/no.yml +1 -0
- data/config/routes.rb +4 -5
- data/cruise_build.sh +6 -2
- data/db/migrate/004_add_period.rb +22 -22
- data/db/migrate/015_add_user_option.rb +5 -19
- data/db/migrate/017_increase_backlog_name_limit.rb +10 -0
- data/db/migrate/021_create_work_accounts.rb +0 -2
- data/db/migrate/20101006092700_rename_backlogs_to_projects.rb +22 -0
- data/db/migrate/20101006092700_rename_backlogs_to_projects.rb~ +22 -0
- data/db/schema.rb +27 -30
- data/db/seeds.rb +7 -0
- data/lib/array_helper.rb +0 -8
- data/lib/class_table_inheritance.rb +8 -7
- data/lib/tasks/backup.rake +3 -3
- data/lib/tasks/jdbc.rake +2 -2
- data/lib/version_from_history.rb +1 -1
- data/public/404.html +23 -7
- data/public/422.html +26 -0
- data/public/500.html +23 -6
- data/public/images/rails.png +0 -0
- data/public/javascripts/controls.js +5 -3
- data/public/javascripts/dragdrop.js +7 -6
- data/public/javascripts/effects.js +8 -13
- data/public/javascripts/prototype.js +3381 -1700
- data/public/javascripts/rails.js +175 -0
- data/public/robots.txt +5 -1
- data/script/rails +6 -0
- data/test/client/login.rb +0 -2
- data/test/client/login_test.rb +1 -1
- data/test/client/setup.rb +25 -24
- data/test/fixtures/{backlogs.yml → projects.yml} +2 -2
- data/test/fixtures/tasks.yml +9 -9
- data/test/fixtures/work_lock_subscriptions.yml +2 -2
- data/test/fixtures/works.yml +7 -7
- data/test/functional/periods_controller_test.rb +1 -1
- data/test/functional/{backlogs_controller_test.rb → projects_controller_test.rb} +22 -21
- data/test/functional/search_controller_test.rb +1 -1
- data/test/functional/tasks_controller_test.rb +17 -17
- data/test/functional/user_controller_test.rb +16 -21
- data/test/functional/welcome_controller_test.rb +4 -3
- data/test/functional/works_controller_test.rb +5 -5
- data/test/integration/user_system_test.rb +1 -1
- data/test/mocks/test/clock.rb +1 -1
- data/test/performance/browsing_test.rb +9 -0
- data/test/performance/common.rb +1 -1
- data/test/test_helper.rb +23 -6
- data/test/test_helper.rb~ +121 -0
- data/test/unit/user_test.rb +3 -3
- data/test/unit/work_test.rb +7 -7
- data/vendor/plugins/assert_cookie/lib/assert_cookie.rb +0 -2
- data/vendor/plugins/{foreign_key_migrations → dynamic_form}/MIT-LICENSE +1 -1
- data/vendor/plugins/dynamic_form/README +13 -0
- data/vendor/plugins/dynamic_form/Rakefile +10 -0
- data/vendor/plugins/dynamic_form/dynamic_form.gemspec +12 -0
- data/vendor/plugins/dynamic_form/init.rb +1 -0
- data/vendor/plugins/dynamic_form/lib/action_view/helpers/dynamic_form.rb +300 -0
- data/vendor/plugins/dynamic_form/lib/action_view/locale/en.yml +8 -0
- data/vendor/plugins/dynamic_form/lib/dynamic_form.rb +5 -0
- data/vendor/plugins/dynamic_form/test/dynamic_form_i18n_test.rb +42 -0
- data/vendor/plugins/dynamic_form/test/dynamic_form_test.rb +370 -0
- data/vendor/plugins/dynamic_form/test/test_helper.rb +9 -0
- data/vendor/plugins/prototype_legacy_helper/lib/prototype_legacy_helper.rb +432 -0
- data/vendor/plugins/prototype_legacy_helper/test/test_prototype_helper.rb +297 -0
- data/vendor/plugins/rails_time/test/debug.log +1 -0
- data/vendor/plugins/{redhillonrails_core → verification}/MIT-LICENSE +1 -1
- data/vendor/plugins/verification/README +34 -0
- data/vendor/plugins/verification/Rakefile +22 -0
- data/vendor/plugins/verification/init.rb +3 -0
- data/vendor/plugins/verification/lib/action_controller/verification.rb +132 -0
- data/vendor/plugins/verification/test/test_helper.rb +18 -0
- data/vendor/plugins/verification/test/verification_test.rb +270 -0
- data/vendor/plugins/will_paginate/lib/will_paginate/collection.rb +1 -1
- metadata +115 -134
- data/Gemfile~ +0 -4
- data/History.txt~ +0 -961
- data/LICENSE_LOCALIZATION +0 -20
- data/README_LOCALIZATION +0 -61
- data/README_RAILS +0 -180
- data/app/views/backlogs/_form.rhtml +0 -44
- data/app/views/backlogs/_name_list.rhtml +0 -5
- data/app/views/backlogs/edit.rhtml +0 -14
- data/app/views/backlogs/list.rhtml +0 -16
- data/app/views/layouts/mwrt002.rhtml +0 -43
- data/config/initializers/mongrel.rb +0 -83
- data/config/preinitializer.rb +0 -20
- data/config/warble.rb~ +0 -84
- data/db/migrate/017_insert_datek_projects.rb +0 -98
- data/lib/change_column_null_migration_fix.rb +0 -15
- data/no_test.rb~ +0 -6
- data/public/dispatch.cgi +0 -10
- data/public/dispatch.fcgi +0 -24
- data/public/dispatch.rb +0 -10
- data/script/about +0 -3
- data/script/breakpointer +0 -3
- data/script/console +0 -3
- data/script/dbconsole +0 -3
- data/script/destroy +0 -3
- data/script/generate +0 -3
- data/script/performance/benchmarker +0 -3
- data/script/performance/profiler +0 -3
- data/script/plugin +0 -3
- data/script/process/inspector +0 -3
- data/script/process/reaper +0 -3
- data/script/process/spawner +0 -3
- data/script/runner +0 -3
- data/script/server +0 -3
- data/test/client/login.rb~ +0 -33
- data/test/mocks/test/user_notify.rb +0 -16
- data/vendor/plugins/foreign_key_migrations/CHANGELOG +0 -103
- data/vendor/plugins/foreign_key_migrations/README +0 -87
- data/vendor/plugins/foreign_key_migrations/about.yml +0 -5
- data/vendor/plugins/foreign_key_migrations/init.rb +0 -1
- data/vendor/plugins/foreign_key_migrations/install.rb +0 -1
- data/vendor/plugins/foreign_key_migrations/lib/foreign_key_migrations.rb +0 -3
- data/vendor/plugins/foreign_key_migrations/lib/red_hill_consulting/foreign_key_migrations/active_record/base.rb +0 -22
- data/vendor/plugins/foreign_key_migrations/lib/red_hill_consulting/foreign_key_migrations/active_record/connection_adapters/abstract_adapter.rb +0 -22
- data/vendor/plugins/foreign_key_migrations/lib/red_hill_consulting/foreign_key_migrations/active_record/connection_adapters/table_definition.rb +0 -28
- data/vendor/plugins/lightwindow_helper/README +0 -33
- data/vendor/plugins/lightwindow_helper/assets/images/ajax-loading.gif +0 -0
- data/vendor/plugins/lightwindow_helper/assets/images/arrow-down.gif +0 -0
- data/vendor/plugins/lightwindow_helper/assets/images/arrow-up.gif +0 -0
- data/vendor/plugins/lightwindow_helper/assets/images/black-70.png +0 -0
- data/vendor/plugins/lightwindow_helper/assets/images/black.png +0 -0
- data/vendor/plugins/lightwindow_helper/assets/images/nextlabel.gif +0 -0
- data/vendor/plugins/lightwindow_helper/assets/images/prevlabel.gif +0 -0
- data/vendor/plugins/lightwindow_helper/assets/javascripts/lightwindow.js +0 -1921
- data/vendor/plugins/lightwindow_helper/assets/stylesheets/lightwindow.css +0 -376
- data/vendor/plugins/lightwindow_helper/init.rb +0 -1
- data/vendor/plugins/lightwindow_helper/install.rb +0 -7
- data/vendor/plugins/lightwindow_helper/lib/lightwindow_helper.rb +0 -31
- data/vendor/plugins/redhillonrails_core/CHANGELOG +0 -150
- data/vendor/plugins/redhillonrails_core/README +0 -124
- data/vendor/plugins/redhillonrails_core/init.rb +0 -19
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/base.rb +0 -54
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/abstract_adapter.rb +0 -31
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/column.rb +0 -21
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/foreign_key_definition.rb +0 -26
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/index_definition.rb +0 -11
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/mysql_adapter.rb +0 -74
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/mysql_column.rb +0 -8
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/postgresql_adapter.rb +0 -99
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/schema_statements.rb +0 -16
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/sqlite3_adapter.rb +0 -9
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/table_definition.rb +0 -27
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema.rb +0 -27
- data/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/schema_dumper.rb +0 -47
- data/vendor/plugins/transactional_migrations/CHANGELOG +0 -9
- data/vendor/plugins/transactional_migrations/MIT-LICENSE +0 -20
- data/vendor/plugins/transactional_migrations/README +0 -15
- data/vendor/plugins/transactional_migrations/about.yml +0 -5
- data/vendor/plugins/transactional_migrations/init.rb +0 -1
- data/vendor/plugins/transactional_migrations/lib/red_hill_consulting/transactional_migrations/active_record/migration.rb +0 -19
@@ -1,124 +0,0 @@
|
|
1
|
-
= RedHill on Rails Core
|
2
|
-
|
3
|
-
RedHill on Rails Core is a plugin that adds the following features:
|
4
|
-
|
5
|
-
* Generic support for foreign-keys;
|
6
|
-
* Mechanism for obtaining indexes directly from a model class; and
|
7
|
-
* A mechanism for determining when <code>Schema.define()</code> is running.
|
8
|
-
|
9
|
-
=== Foreign Key Support
|
10
|
-
|
11
|
-
The plugin provides two mechanisms for adding foreign keys as well as
|
12
|
-
preserving foreign keys when performing a schema dump. (Using SQL-92 syntax and
|
13
|
-
as such should be compatible with most databases that support foreign-key
|
14
|
-
constraints.)
|
15
|
-
|
16
|
-
The first mechanism for creating foreign-keys allows you to add a foreign key
|
17
|
-
when defining a table. For example:
|
18
|
-
|
19
|
-
create_table :orders do |t|
|
20
|
-
...
|
21
|
-
t.foreign_key :customer_id, :customers, :id
|
22
|
-
end
|
23
|
-
|
24
|
-
You also have the option of specifying what to do on delete/update using
|
25
|
-
<code>:on_delete</code>/<code>:on_update</code>, respectively to one of: <code>:cascade</code>; <code>:restrict</code>; and <code>:set_null</code>:
|
26
|
-
|
27
|
-
create_table :orders do |t|
|
28
|
-
...
|
29
|
-
t.foreign_key :customer_id, :customers, :id, :on_delete => :set_null, :on_update => :cascade
|
30
|
-
end
|
31
|
-
|
32
|
-
The second method allows you to create arbitrary foreign-keys at any time:
|
33
|
-
|
34
|
-
add_foreign_key(:orders, :customer_id, :customers, :id, :on_delete => :set_null, :on_update => :cascade)
|
35
|
-
|
36
|
-
In either case, if your database supports deferred foreign keys (for example PostgreSQL) you can specify this as well:
|
37
|
-
|
38
|
-
t.foreign_key :customer_id, :customers, :id, :deferrable => true
|
39
|
-
add_foreign_key(:orders, :customer_id, :customers, :id, :deferrable => true)
|
40
|
-
|
41
|
-
By default, the foreign key will be assigned a name by the underlying database. However, if this doesn't suit
|
42
|
-
your needs, you can override the default assignment using the <code>:name</code> option:
|
43
|
-
|
44
|
-
add_foreign_key(:orders, :customer_id, :customers, :id, :on_delete => :set_null, :on_update => :cascade, <strong>:name => :orders_customer_id_foreign_key<strong>)
|
45
|
-
|
46
|
-
You can also query the foreign keys for a model yourself by calling <code>foreign_keys()</code>:
|
47
|
-
|
48
|
-
Order.foreign_keys
|
49
|
-
|
50
|
-
Or for an arbitrary table by calling <code>foreign_keys(table_name)</code> on a database adapter.
|
51
|
-
|
52
|
-
Either method returns an array of the following meta-data:
|
53
|
-
|
54
|
-
* +name+ - The name of the foreign key constraint;
|
55
|
-
* +table_name+ - The table for which the foreign-key was generated;
|
56
|
-
* +column_names+ - The column names in the table;
|
57
|
-
* +references_table_name+ - The table referenced by the foreign-key; and
|
58
|
-
* +references_column_names+ - The columns names in the referenced table.
|
59
|
-
|
60
|
-
If you need to drop a foreign-key, use:
|
61
|
-
|
62
|
-
remove_foreign_key :orders, :orders_ordered_by_id_fkey
|
63
|
-
|
64
|
-
The plugin also ensures that all foreign keys are output when performing a
|
65
|
-
schema dump. This happens automatically when running <code>rake migrate</code> or
|
66
|
-
<code>rake db:schema:dump</code>. This has particular implications when running
|
67
|
-
unit tests that contain fixtures. To ensure the test data is correctly reset after
|
68
|
-
each test, you should list your fixtures in order of parent->child. For example:
|
69
|
-
|
70
|
-
fixtures :customers, :products, :orders, :order_lines
|
71
|
-
|
72
|
-
Rails will then set-up and tear-down the fixtures in the correct sequence.
|
73
|
-
|
74
|
-
The plugin fully supports and understands the following active-record
|
75
|
-
configuration properties:
|
76
|
-
|
77
|
-
* <code>config.active_record.pluralize_table_names</code>
|
78
|
-
* <code>config.active_record.table_name_prefix</code>
|
79
|
-
* <code>config.active_record.table_name_suffix</code>
|
80
|
-
|
81
|
-
=== Model Indexes
|
82
|
-
|
83
|
-
ActiveRecord::Base already provides a method on connection for obtaining the
|
84
|
-
indexes for a given table. This plugin now makes it possible to obtain the
|
85
|
-
indexes for a given model--<code>ActiveRecord::Base</code>--class. For example:
|
86
|
-
|
87
|
-
Invoice.indexes
|
88
|
-
|
89
|
-
Would return all the indexes for the +invoices+ table.
|
90
|
-
|
91
|
-
=== Schema Defining
|
92
|
-
|
93
|
-
The plugin also adds a method--<code>defining?()</code>--to
|
94
|
-
<code>ActiveRecord::Schema</code> to indicate when <code>define()</code> is running. This is necessary
|
95
|
-
as some migration plugins must change their behaviour accordingly.
|
96
|
-
|
97
|
-
=== Case-insensitive Indexes
|
98
|
-
|
99
|
-
For PostgreSQL, you can add an option <code>:case_sensitive => false</code> to <code>add_index</code>
|
100
|
-
which will generate an expression index of the form:
|
101
|
-
|
102
|
-
LOWER(column_name)
|
103
|
-
|
104
|
-
This means finder queries of the form:
|
105
|
-
|
106
|
-
WHERE LOWER(column_name) = LOWER(?)
|
107
|
-
|
108
|
-
are able to use the indexes rather require, in the worst case, full-table scans.
|
109
|
-
|
110
|
-
Note also that this ties in well with Rails built-in support for case-insensitive searching:
|
111
|
-
|
112
|
-
validates_uniqueness_of :name, :case_sensitive => false
|
113
|
-
|
114
|
-
=== See Also
|
115
|
-
|
116
|
-
* Foreign Key Associations (foreign_key_associations)
|
117
|
-
* Foreign Key Migrations (foreign_key_migrations)
|
118
|
-
* Row Version Migrations (row_version_migrations)
|
119
|
-
* Schema Validations (schema_validations)
|
120
|
-
|
121
|
-
=== License
|
122
|
-
|
123
|
-
This plugin is copyright 2006 by RedHill Consulting, Pty. Ltd. and is released
|
124
|
-
under the MIT license.
|
@@ -1,19 +0,0 @@
|
|
1
|
-
ActiveRecord::Base.send(:include, RedHillConsulting::Core::ActiveRecord::Base)
|
2
|
-
ActiveRecord::Schema.send(:include, RedHillConsulting::Core::ActiveRecord::Schema)
|
3
|
-
ActiveRecord::SchemaDumper.send(:include, RedHillConsulting::Core::ActiveRecord::SchemaDumper)
|
4
|
-
ActiveRecord::ConnectionAdapters::IndexDefinition.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::IndexDefinition)
|
5
|
-
ActiveRecord::ConnectionAdapters::TableDefinition.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::TableDefinition)
|
6
|
-
ActiveRecord::ConnectionAdapters::Column.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::Column)
|
7
|
-
ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::AbstractAdapter)
|
8
|
-
ActiveRecord::ConnectionAdapters::SchemaStatements.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::SchemaStatements)
|
9
|
-
|
10
|
-
if defined?(ActiveRecord::ConnectionAdapters::PostgreSQLAdapter) then
|
11
|
-
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::PostgresqlAdapter)
|
12
|
-
end
|
13
|
-
if defined?(ActiveRecord::ConnectionAdapters::MysqlAdapter) then
|
14
|
-
ActiveRecord::ConnectionAdapters::MysqlColumn.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::MysqlColumn)
|
15
|
-
ActiveRecord::ConnectionAdapters::MysqlAdapter.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::MysqlAdapter)
|
16
|
-
end
|
17
|
-
if defined?(ActiveRecord::ConnectionAdapters::SQLite3Adapter) then
|
18
|
-
ActiveRecord::ConnectionAdapters::SQLite3Adapter.send(:include, RedHillConsulting::Core::ActiveRecord::ConnectionAdapters::Sqlite3Adapter)
|
19
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module RedHillConsulting::Core::ActiveRecord
|
2
|
-
module Base
|
3
|
-
def self.included(base)
|
4
|
-
base.extend(ClassMethods)
|
5
|
-
end
|
6
|
-
|
7
|
-
module ClassMethods
|
8
|
-
def self.extended(base)
|
9
|
-
class << base
|
10
|
-
alias_method_chain :columns, :redhillonrails_core unless method_defined?(:columns_without_redhillonrails_core)
|
11
|
-
alias_method_chain :abstract_class?, :redhillonrails_core unless method_defined?(:abstract_class_without_redhillonrails_core?)
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
def base_class?
|
16
|
-
self == base_class
|
17
|
-
end
|
18
|
-
|
19
|
-
def abstract_class_with_redhillonrails_core?
|
20
|
-
abstract_class_without_redhillonrails_core? || !(name =~ /^Abstract/).nil?
|
21
|
-
end
|
22
|
-
|
23
|
-
def columns_with_redhillonrails_core
|
24
|
-
unless @columns
|
25
|
-
columns_without_redhillonrails_core
|
26
|
-
cols = columns_hash
|
27
|
-
indexes.each do |index|
|
28
|
-
column_name = index.columns.reverse.detect { |name| name !~ /_id$/ } || index.columns.last
|
29
|
-
column = cols[column_name]
|
30
|
-
column.case_sensitive = index.case_sensitive?
|
31
|
-
column.unique_scope = index.columns.reject { |name| name == column_name } if index.unique
|
32
|
-
end
|
33
|
-
end
|
34
|
-
@columns
|
35
|
-
end
|
36
|
-
|
37
|
-
def pluralized_table_name(table_name)
|
38
|
-
ActiveRecord::Base.pluralize_table_names ? table_name.to_s.pluralize : table_name
|
39
|
-
end
|
40
|
-
|
41
|
-
def indexes
|
42
|
-
@indexes ||= connection.indexes(table_name)
|
43
|
-
end
|
44
|
-
|
45
|
-
def foreign_keys
|
46
|
-
@foreign_keys ||= connection.foreign_keys(table_name, "#{name} Foreign Keys")
|
47
|
-
end
|
48
|
-
|
49
|
-
def reverse_foreign_keys
|
50
|
-
connection.reverse_foreign_keys(table_name, "#{name} Reverse Foreign Keys")
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
module RedHillConsulting::Core::ActiveRecord::ConnectionAdapters
|
2
|
-
module AbstractAdapter
|
3
|
-
def self.included(base)
|
4
|
-
base.module_eval do
|
5
|
-
alias_method_chain :drop_table, :redhillonrails_core
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
def foreign_keys(table_name, name = nil)
|
10
|
-
[]
|
11
|
-
end
|
12
|
-
|
13
|
-
def reverse_foreign_keys(table_name, name = nil)
|
14
|
-
[]
|
15
|
-
end
|
16
|
-
|
17
|
-
def add_foreign_key(table_name, column_names, references_table_name, references_column_names, options = {})
|
18
|
-
foreign_key = ForeignKeyDefinition.new(options[:name], table_name, column_names, ActiveRecord::Migrator.proper_table_name(references_table_name), references_column_names, options[:on_update], options[:on_delete], options[:deferrable])
|
19
|
-
execute "ALTER TABLE #{table_name} ADD #{foreign_key}"
|
20
|
-
end
|
21
|
-
|
22
|
-
def remove_foreign_key(table_name, foreign_key_name)
|
23
|
-
execute "ALTER TABLE #{table_name} DROP CONSTRAINT #{foreign_key_name}"
|
24
|
-
end
|
25
|
-
|
26
|
-
def drop_table_with_redhillonrails_core(name, options = {})
|
27
|
-
reverse_foreign_keys(name).each { |foreign_key| remove_foreign_key(foreign_key.table_name, foreign_key.name) }
|
28
|
-
drop_table_without_redhillonrails_core(name, options)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
module RedHillConsulting::Core::ActiveRecord::ConnectionAdapters
|
2
|
-
module Column
|
3
|
-
attr_accessor :unique_scope
|
4
|
-
attr_accessor :case_sensitive
|
5
|
-
alias case_sensitive? case_sensitive
|
6
|
-
|
7
|
-
def unique?
|
8
|
-
!unique_scope.nil?
|
9
|
-
end
|
10
|
-
|
11
|
-
def required_on
|
12
|
-
if null
|
13
|
-
nil
|
14
|
-
elsif default.nil?
|
15
|
-
:save
|
16
|
-
else
|
17
|
-
:update
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,26 +0,0 @@
|
|
1
|
-
module RedHillConsulting::Core::ActiveRecord::ConnectionAdapters
|
2
|
-
class ForeignKeyDefinition < Struct.new(:name, :table_name, :column_names, :references_table_name, :references_column_names, :on_update, :on_delete, :deferrable)
|
3
|
-
ACTIONS = { :cascade => "CASCADE", :restrict => "RESTRICT", :set_null => "SET NULL", :set_default => "SET DEFAULT", :no_action => "NO ACTION" }.freeze
|
4
|
-
|
5
|
-
def to_dump
|
6
|
-
dump = "add_foreign_key"
|
7
|
-
dump << " #{table_name.inspect}, [#{column_names.collect{ |name| name.inspect }.join(', ')}]"
|
8
|
-
dump << ", #{references_table_name.inspect}, [#{references_column_names.collect{ |name| name.inspect }.join(', ')}]"
|
9
|
-
dump << ", :on_update => :#{on_update}" if on_update
|
10
|
-
dump << ", :on_delete => :#{on_delete}" if on_delete
|
11
|
-
dump << ", :deferrable => #{deferrable}" if deferrable
|
12
|
-
dump << ", :name => #{name.inspect}" if name
|
13
|
-
dump
|
14
|
-
end
|
15
|
-
|
16
|
-
def to_sql
|
17
|
-
sql = name ? "CONSTRAINT #{name} " : ""
|
18
|
-
sql << "FOREIGN KEY (#{Array(column_names).join(", ")}) REFERENCES #{references_table_name} (#{Array(references_column_names).join(", ")})"
|
19
|
-
sql << " ON UPDATE #{ACTIONS[on_update]}" if on_update
|
20
|
-
sql << " ON DELETE #{ACTIONS[on_delete]}" if on_delete
|
21
|
-
sql << " DEFERRABLE" if deferrable
|
22
|
-
sql
|
23
|
-
end
|
24
|
-
alias :to_s :to_sql
|
25
|
-
end
|
26
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module RedHillConsulting::Core::ActiveRecord::ConnectionAdapters
|
2
|
-
module IndexDefinition
|
3
|
-
def case_sensitive?
|
4
|
-
@case_sensitive.nil? ? true : @case_sensitive
|
5
|
-
end
|
6
|
-
|
7
|
-
def case_sensitive=(case_sensitive)
|
8
|
-
@case_sensitive = case_sensitive
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
module RedHillConsulting::Core::ActiveRecord::ConnectionAdapters
|
2
|
-
module MysqlAdapter
|
3
|
-
def self.included(base)
|
4
|
-
base.class_eval do
|
5
|
-
alias_method_chain :remove_column, :redhillonrails_core
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
def remove_foreign_key(table_name, foreign_key_name)
|
10
|
-
execute "ALTER TABLE #{table_name} DROP FOREIGN KEY #{foreign_key_name}"
|
11
|
-
end
|
12
|
-
|
13
|
-
def remove_column_with_redhillonrails_core(table_name, column_name)
|
14
|
-
foreign_keys(table_name).select { |foreign_key| foreign_key.column_names.include?(column_name.to_s) }.each do |foreign_key|
|
15
|
-
remove_foreign_key(table_name, foreign_key.name)
|
16
|
-
end
|
17
|
-
remove_column_without_redhillonrails_core(table_name, column_name)
|
18
|
-
end
|
19
|
-
|
20
|
-
def foreign_keys(table_name, name = nil)
|
21
|
-
results = execute("SHOW CREATE TABLE `#{table_name}`", name)
|
22
|
-
|
23
|
-
foreign_keys = []
|
24
|
-
|
25
|
-
results.each do |row|
|
26
|
-
row[1].each do |line|
|
27
|
-
if line =~ /^ CONSTRAINT [`"](.+?)[`"] FOREIGN KEY \([`"](.+?)[`"]\) REFERENCES [`"](.+?)[`"] \((.+?)\)( ON DELETE (.+?))?( ON UPDATE (.+?))?,?$/
|
28
|
-
name = $1
|
29
|
-
column_names = $2
|
30
|
-
references_table_name = $3
|
31
|
-
references_column_names = $4
|
32
|
-
on_update = $8
|
33
|
-
on_delete = $6
|
34
|
-
on_update = on_update.downcase.gsub(' ', '_').to_sym if on_update
|
35
|
-
on_delete = on_delete.downcase.gsub(' ', '_').to_sym if on_delete
|
36
|
-
|
37
|
-
foreign_keys << ForeignKeyDefinition.new(name,
|
38
|
-
table_name, column_names.gsub('`', '').split(', '),
|
39
|
-
references_table_name, references_column_names.gsub('`', '').split(', '),
|
40
|
-
on_update, on_delete)
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
foreign_keys
|
46
|
-
end
|
47
|
-
|
48
|
-
def reverse_foreign_keys(table_name, name = nil)
|
49
|
-
results = execute(<<-SQL, name)
|
50
|
-
SELECT constraint_name, table_name, column_name, referenced_table_name, referenced_column_name
|
51
|
-
FROM information_schema.key_column_usage
|
52
|
-
WHERE table_schema = SCHEMA()
|
53
|
-
AND referenced_table_schema = table_schema
|
54
|
-
AND referenced_table_name = '#{table_name}'
|
55
|
-
ORDER BY constraint_name, ordinal_position;
|
56
|
-
SQL
|
57
|
-
|
58
|
-
current_foreign_key = nil
|
59
|
-
foreign_keys = []
|
60
|
-
|
61
|
-
results.each do |row|
|
62
|
-
if current_foreign_key != row[0]
|
63
|
-
foreign_keys << ForeignKeyDefinition.new(row[0], row[1], [], row[3], [])
|
64
|
-
current_foreign_key = row[0]
|
65
|
-
end
|
66
|
-
|
67
|
-
foreign_keys.last.column_names << row[2]
|
68
|
-
foreign_keys.last.references_column_names << row[4]
|
69
|
-
end
|
70
|
-
|
71
|
-
foreign_keys
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
@@ -1,99 +0,0 @@
|
|
1
|
-
module RedHillConsulting::Core::ActiveRecord::ConnectionAdapters
|
2
|
-
module PostgresqlAdapter
|
3
|
-
def self.included(base)
|
4
|
-
base.class_eval do
|
5
|
-
alias_method_chain :indexes, :redhillonrails_core
|
6
|
-
end
|
7
|
-
end
|
8
|
-
|
9
|
-
def add_index(table_name, column_name, options = {})
|
10
|
-
column_names = Array(column_name)
|
11
|
-
index_name = index_name(table_name, :column => column_names)
|
12
|
-
|
13
|
-
if Hash === options # legacy support, since this param was a string
|
14
|
-
index_type = options[:unique] ? "UNIQUE" : ""
|
15
|
-
index_name = options[:name] || index_name
|
16
|
-
else
|
17
|
-
index_type = options
|
18
|
-
end
|
19
|
-
|
20
|
-
quoted_column_names = column_names.map { |e| options[:case_sensitive] == false && e.to_s !~ /_id$/ ? "LOWER(#{quote_column_name(e)})" : quote_column_name(e) }
|
21
|
-
|
22
|
-
execute "CREATE #{index_type} INDEX #{quote_column_name(index_name)} ON #{table_name} (#{quoted_column_names.join(", ")})"
|
23
|
-
end
|
24
|
-
|
25
|
-
def indexes_with_redhillonrails_core(table_name, name = nil)
|
26
|
-
indexes = indexes_without_redhillonrails_core(table_name, name)
|
27
|
-
result = query(<<-SQL, name)
|
28
|
-
SELECT c2.relname, i.indisunique, pg_catalog.pg_get_indexdef(i.indexrelid, 0, true)
|
29
|
-
FROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i
|
30
|
-
WHERE c.relname = '#{table_name}'
|
31
|
-
AND c.oid = i.indrelid AND i.indexrelid = c2.oid
|
32
|
-
AND i.indisprimary = 'f'
|
33
|
-
AND i.indexprs IS NOT NULL
|
34
|
-
ORDER BY 1
|
35
|
-
SQL
|
36
|
-
|
37
|
-
result.each do |row|
|
38
|
-
if row[2]=~ /\((.*LOWER\(.*::text\).*)\)$/i
|
39
|
-
indexes.delete_if { |index| index.name == row[0] }
|
40
|
-
column_names = $1.split(", ").map { |name| name =~ /^LOWER\((.*)::text\)$/i ? $1 : name }
|
41
|
-
index = ActiveRecord::ConnectionAdapters::IndexDefinition.new(table_name, row[0], row[1] == "t", column_names)
|
42
|
-
index.case_sensitive = false
|
43
|
-
indexes << index
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
indexes
|
48
|
-
end
|
49
|
-
|
50
|
-
def foreign_keys(table_name, name = nil)
|
51
|
-
load_foreign_keys(<<-SQL, name)
|
52
|
-
SELECT f.conname, pg_get_constraintdef(f.oid), t.relname
|
53
|
-
FROM pg_class t, pg_constraint f
|
54
|
-
WHERE f.conrelid = t.oid
|
55
|
-
AND f.contype = 'f'
|
56
|
-
AND t.relname = '#{table_name}'
|
57
|
-
SQL
|
58
|
-
end
|
59
|
-
|
60
|
-
def reverse_foreign_keys(table_name, name = nil)
|
61
|
-
load_foreign_keys(<<-SQL, name)
|
62
|
-
SELECT f.conname, pg_get_constraintdef(f.oid), t2.relname
|
63
|
-
FROM pg_class t, pg_class t2, pg_constraint f
|
64
|
-
WHERE f.confrelid = t.oid
|
65
|
-
AND f.conrelid = t2.oid
|
66
|
-
AND f.contype = 'f'
|
67
|
-
AND t.relname = '#{table_name}'
|
68
|
-
SQL
|
69
|
-
end
|
70
|
-
|
71
|
-
private
|
72
|
-
|
73
|
-
def load_foreign_keys(sql, name = nil)
|
74
|
-
foreign_keys = []
|
75
|
-
|
76
|
-
query(sql, name).each do |row|
|
77
|
-
if row[1] =~ /^FOREIGN KEY \((.+?)\) REFERENCES (.+?)\((.+?)\)( ON UPDATE (.+?))?( ON DELETE (.+?))?( (DEFERRABLE|NOT DEFERRABLE))?$/
|
78
|
-
name = row[0]
|
79
|
-
from_table_name = row[2]
|
80
|
-
column_names = $1
|
81
|
-
references_table_name = $2
|
82
|
-
references_column_names = $3
|
83
|
-
on_update = $5
|
84
|
-
on_delete = $7
|
85
|
-
deferrable = $9 == "DEFERRABLE"
|
86
|
-
on_update = on_update.downcase.gsub(' ', '_').to_sym if on_update
|
87
|
-
on_delete = on_delete.downcase.gsub(' ', '_').to_sym if on_delete
|
88
|
-
|
89
|
-
foreign_keys << ForeignKeyDefinition.new(name,
|
90
|
-
from_table_name, column_names.split(', '),
|
91
|
-
references_table_name.sub(/^"(.*)"$/, '\1'), references_column_names.split(', '),
|
92
|
-
on_update, on_delete, deferrable)
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
|
-
foreign_keys
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|