ghazel-ar-extensions 0.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/ChangeLog +145 -0
  2. data/README +169 -0
  3. data/Rakefile +61 -0
  4. data/config/database.yml +7 -0
  5. data/config/database.yml.template +7 -0
  6. data/config/mysql.schema +72 -0
  7. data/config/postgresql.schema +39 -0
  8. data/db/migrate/generic_schema.rb +97 -0
  9. data/db/migrate/mysql_schema.rb +32 -0
  10. data/db/migrate/oracle_schema.rb +5 -0
  11. data/db/migrate/version.rb +4 -0
  12. data/init.rb +31 -0
  13. data/lib/ar-extensions/adapters/abstract_adapter.rb +146 -0
  14. data/lib/ar-extensions/adapters/mysql.rb +10 -0
  15. data/lib/ar-extensions/adapters/oracle.rb +14 -0
  16. data/lib/ar-extensions/adapters/postgresql.rb +9 -0
  17. data/lib/ar-extensions/adapters/sqlite.rb +7 -0
  18. data/lib/ar-extensions/create_and_update/mysql.rb +7 -0
  19. data/lib/ar-extensions/create_and_update.rb +509 -0
  20. data/lib/ar-extensions/csv.rb +309 -0
  21. data/lib/ar-extensions/delete/mysql.rb +3 -0
  22. data/lib/ar-extensions/delete.rb +143 -0
  23. data/lib/ar-extensions/extensions.rb +513 -0
  24. data/lib/ar-extensions/finder_options/mysql.rb +6 -0
  25. data/lib/ar-extensions/finder_options.rb +275 -0
  26. data/lib/ar-extensions/finders.rb +94 -0
  27. data/lib/ar-extensions/foreign_keys.rb +70 -0
  28. data/lib/ar-extensions/fulltext/mysql.rb +44 -0
  29. data/lib/ar-extensions/fulltext.rb +62 -0
  30. data/lib/ar-extensions/import/mysql.rb +50 -0
  31. data/lib/ar-extensions/import/postgresql.rb +0 -0
  32. data/lib/ar-extensions/import/sqlite.rb +22 -0
  33. data/lib/ar-extensions/import.rb +348 -0
  34. data/lib/ar-extensions/insert_select/mysql.rb +7 -0
  35. data/lib/ar-extensions/insert_select.rb +178 -0
  36. data/lib/ar-extensions/synchronize.rb +30 -0
  37. data/lib/ar-extensions/temporary_table/mysql.rb +3 -0
  38. data/lib/ar-extensions/temporary_table.rb +131 -0
  39. data/lib/ar-extensions/union/mysql.rb +6 -0
  40. data/lib/ar-extensions/union.rb +204 -0
  41. data/lib/ar-extensions/util/sql_generation.rb +27 -0
  42. data/lib/ar-extensions/util/support_methods.rb +32 -0
  43. data/lib/ar-extensions/version.rb +9 -0
  44. data/lib/ar-extensions.rb +5 -0
  45. metadata +110 -0
data/ChangeLog ADDED
@@ -0,0 +1,145 @@
1
+ 2009-07-22 zdennis <zach.dennis@gmail.com>
2
+
3
+ * Forgot to push past commit of fixing #sanitize_sql method signatures to supported passing in a table_name. This satisfies the change to the ActiveRecord API in Rails commit 489abfd3b23f3c4b3de86aeb3bde3970771c001b on April 20th.
4
+
5
+ 2009-04-17 blythedunham <blythedunham@gmail.com>
6
+
7
+ * Added MySQL support for save, create, replace options - :ignore, :on_duplicate_key_update, :keywords, :reload, :keywords, :pre_sql, :post_sql
8
+ * Added MySQL support for find options: :keywords, :pre_sql, :post_sql, :index_hint
9
+ * Added MySQL support for find_union and count_union
10
+ * Added MySQL support for insert_select
11
+ * Added MySQL support for delete_duplicates and delete_all :batch_size => X
12
+ * Updated :on_duplicate_update_key to accept a string in addition to array
13
+ * Fixed Find Extension Range bug to exclude end when ... used instead of ..
14
+
15
+ 2009-03-16 zdennis <zach.dennis@gmail.com>
16
+
17
+ * fixed Rails 2.3.1 and 2.3.2 compatibility issue (Stephen Heuer)
18
+
19
+ 2009-02-09 zdennis <zach.dennis@gmail.com>
20
+
21
+ * fixed issue in http://zdennis.lighthouseapp.com/projects/14379/tickets/14-join-table-conditions-broken
22
+ * Updated usage of Inflector to point to ActiveSupport::Inflector
23
+ * Fixed bug where finder conditions which use arext-suffixed keys and normal field keys would fail when using a conditions hash. (Gabe da Silveira)
24
+ * added timestamps options to not automatically add timestamps even if record timestamps is disabled in ActiveRecord::Base (Thibaud Guillaume-Gentil)
25
+ * Updated to use alias_method_chain so that multiple aliased finders remain intact (Marcus Crafter)
26
+
27
+ 2007-07-20 zdennis <zdennis@dhcp-22.atomicobject.localnet>
28
+
29
+ * Added patch from Michael Flester to fix bug with created_at/updated_at fields to use proper timezone.
30
+
31
+ 2007-07-18 zdennis <zdennis@dhcp-22.atomicobject.localnet>
32
+
33
+ * Added patch for Oracle support from Michael Flester.
34
+
35
+ 2007-05-05 zdennis <zdennis@elijah.local>
36
+
37
+ * Added ActiveRecord::Base::AbstractAdapter#synchronize method which allows a mass re-synchronization of ActiveRecord instances. This is similar to ActiveRecord::Base#reload except that it works on multiple instances at a time rather then one. This sends one query for all instances rather then 1 per instance reloaded.
38
+
39
+ * Fixed bug with URI encoded strings with a workaround in the Comparison extension. ActiveRecord needs to be fixed to not use the String#% method so strings that do contains percentage signs will not fail
40
+
41
+ * Applied patch from Grant Goodale to allow the Like extension to support arrays when using the '_contains' suffix
42
+
43
+ 2007-03-14 zdennis <zdennis@elijah.xrite.com>
44
+
45
+ * Fixed a bug by renaming the alias for the ActiveRecord::Base#quote method in finders.rb. See rubyforge bug #8996
46
+
47
+ * Made a .gemspec for ar-extensions
48
+
49
+ 2007-03-13 zdennis <zdennis@elijah>
50
+
51
+ * Added :datetime searching support for better finder support.
52
+
53
+ 2007-02-11 zdennis <zdennis@admin.aries>
54
+
55
+ * Updated to_csv and import functionality to work with Sqlite, Sqlite3, PostgreSQL and MySQL
56
+
57
+ * Updated RDOC for import, to_csv, better finders, temporary tables and foreign key support
58
+
59
+ 2007-01-29 zdennis <zdennis@mktec.com>
60
+
61
+ * Added initial support for temporary tables and permanent like tables.
62
+
63
+ 2007-01-24 zdennis <zdennis@mktec.com>
64
+
65
+ * Added dependency for Mocha 0.4.0 or higher for testing
66
+
67
+ * Fixed bug for import functionality where it was never actually splitting up values correctly (thx to Mark Van Holstyn!!)
68
+
69
+ 2007-01-09 zdennis <zdennis@aries>
70
+
71
+ * Added support for embedded to_csv includes
72
+
73
+ 2007-01-07 zdennis <zdennis@aries>
74
+
75
+ * Added fix to init.rb to only load CSV functionality if FasterCSV
76
+ is available, otherwise print a message to STDERR and continue.
77
+
78
+ * Added fix to tests/boot.rb which solves fixture_path issues in
79
+ ActiveRecord 1.14.4 and earlier. The fix is included Rails trunk
80
+ and will be available in Rails 1.2.
81
+
82
+ 2007-01-05 zdennis <zdennis@aries>
83
+
84
+ * Added ActiveRecord::Extensions::VERSION module which has the following constants: MAJOR, MINOR, REVISION
85
+
86
+ * Running rake tests are now smart enough to rebuild the database if they are required based on schema_info table.
87
+
88
+ * Added schema_info table for test database schemas.
89
+
90
+ 2006-12-29 zdennis <zdennis@aries>
91
+
92
+ * Updated the Rakefile to run an external ruby process when running test files rather then in the same ruby process that runs the Rakefile
93
+
94
+ * Updated the directory structure of lib/ to solve namespace issues.
95
+
96
+ 2006-12-22 Zach Dennis <zdennis@silver.dennis.network>
97
+
98
+ * Added rake tasks for sqlite and sqlite3 databases
99
+
100
+ * Added "does_not_match" as a suffix to better finders when working with Regular Expressions
101
+
102
+ * Added "not_between" suffix to better finders when working with Ranges
103
+
104
+ 2006-12-17 zdennis <zdennis@aries>
105
+
106
+ * Added :only and :except options to to_csv method. Forcing
107
+ compatibility with http://blog.integralimpressions.com/articles/2006/09/01/tocsv-plugin
108
+
109
+ * Changed to_csv option :headers take a boolean rather then an
110
+ array of column names.
111
+
112
+ * Added rake task db:prepare_<adapter_name> to build test
113
+ database.
114
+
115
+ 2006-12-16 Zach Dennis <zdennis@silver.dennis.network>
116
+
117
+ * Added more tests for better finder support
118
+
119
+ * Added to_csv support for Arrays returned by ActiveRecord::Base.find
120
+
121
+ * Refactored ActiveRecord::Extensions::Registry to use an Array instead of hash
122
+
123
+ 2006-12-06 Zach Dennis <zdennis@silver.dennis.network>
124
+
125
+ * PostgreSQL has tested support for everything MySQL has except for Full Text Searching. This is not implemented.
126
+
127
+ * Refactored how import and full text searching implementation is handled, this is largely handled by duck typing certain method calls.
128
+
129
+ * Added generic import support for any adapter that doesn't support multi-value insert statements. This provides generic support which is guaranteed to be no slower then ActiveRecord#create.
130
+
131
+ 2006-11-23 Zach Dennis <zdennis@silver.dennis.network>
132
+
133
+ * Added finder support for PostgreSQL including Regexp Searching. (No full text searching though)
134
+
135
+ * Fixed bug in finders.rb where NULL searches were not correctly being translated into IS NULL when doing { :column => nil }
136
+
137
+ 2006-11-20 Zach Dennis <zach.dennis@gmail.com>
138
+
139
+ * Refactored core finder components out into ActiveRecord extensions
140
+
141
+ * Duck typing support for any object that is passed in to a conditions hash. ie: MyModel.find( :all, :conditions=>{ :name=>NameSearchObject.new } )
142
+
143
+ * Duck typing support for any object that is passed in as a condition. ie: MyModel.find( :all, :conditions=>SearchObject.new )
144
+
145
+
data/README ADDED
@@ -0,0 +1,169 @@
1
+ *ar-extensions is not compatible and is not being developed for Rails 3. Please use the activerecord-import gem which supports the same interface.*
2
+
3
+ LICENSE
4
+ ----------
5
+ This is licensed under the ruby license.
6
+
7
+ Author: Zach Dennis
8
+ Web Site: http://www.continuousthinking.com/tags/arext
9
+ Email: zach.dennis@gmail.com
10
+
11
+ - For How-To information see http://www.continuousthinking.com/tags/arext
12
+ - For project information and feedback please consult http://rubyforge.org/projects/arext/
13
+ - For release information please see below
14
+
15
+ ActiveRecord::Extensions 0.9.0, 0.9.1
16
+ ------------------------------
17
+ April 17, 2009
18
+ - Added MySQL support for save, create, replace options - :ignore, :on_duplicate_key_update, :keywords, :reload, :keywords, :pre_sql, :post_sql
19
+ - Added MySQL support for find options: :keywords, :pre_sql, :post_sql, :index_hint
20
+ - Added MySQL support for find_union and count_union
21
+ - Added MySQL support for insert_select
22
+ - Added MySQL support for delete_duplicates and delete_all :batch_size => X
23
+ - Updated :on_duplicate_update_key to accept a string in addition to array
24
+ - Fixed Find Extension Range bug to exclude end when ... used instead of ..
25
+
26
+ ActiveRecord::Extensions 0.8.2
27
+ ------------------------------
28
+ March 16th, 2009
29
+ - Rails 2.3.1 and 2.3.2 compatibility added
30
+ - Rails 2.1.2 and 2.2.2 compatibility preserved
31
+
32
+ AciveRecord::Extensions 0.7.0
33
+ -----------------------------
34
+ July 20th, 2007
35
+ - Fixes timezone issue (thanks Michael Flester)
36
+ - Adds better finder and import support for Oracle (thanks Michael Flester)
37
+ - Committed patch to fix MySQL query padding, thanks to Gabe da Silveira
38
+ - Added functionality for MySQL to work with created_on, created_at, updated_on or updated_at fields
39
+ - Added more test coverage for import functionality
40
+
41
+ ActiveRecord::Extensions 0.6.0
42
+ ------------------------------
43
+ May 5th, 2007
44
+ - Fixed bug with URI escaped strings and the Comparison better finder extension
45
+ - Added support for arrays with the Like better finder extension when using the '_contains' suffix
46
+ - Added 'synchronize' support for ActiveRecord::Base instances when using Import functionality
47
+
48
+ ActiveRecord::Extensions 0.5.2
49
+ ------------------------------
50
+ March 14th, 2007
51
+ - Fixed Rubyforge bug #8996 by renaming alias in finders.rb to the ActiveRecord::Base#quote method
52
+
53
+ ActiveRecord::Extensions 0.5.1
54
+ ------------------------------
55
+ March 14th, 2007
56
+ - Released as a rubygem
57
+ - Added a .gemspec file
58
+
59
+ ActiveRecord::Extensions 0.5.0
60
+ ------------------------------
61
+ March 13th, 2007
62
+ - Added Time based query support which works on ActiveRecord columns which match a type supported by :datetime
63
+
64
+ ActiveRecord::Extensions 0.4.0
65
+ ------------------------------
66
+ February 11th, 2007
67
+ - Added to_csv functionality
68
+ - Added temporary table support (MySQL)
69
+ - Added foreign key support (MySQL)
70
+ - Updated tests to keep schema information. Test database will automatically rebuild themselves if they are out of sync
71
+ - Added dependency for Mocha 0.4.0 or higher for tests
72
+
73
+ ActiveRecord::Extensions 0.3.0
74
+ ------------------------------
75
+ December 29th, 2006
76
+ - Updates to the lib/ directory structure to avoid namespace issues.
77
+ - Updates to the Rakefile to run an external ruby process for tests rather then the same
78
+ ruby process that runs the rake tasks
79
+
80
+ ActiveRecord::Extensions 0.2.0
81
+ ------------------------------
82
+ December 22nd, 2006
83
+ - Updates to_csv method for arrays returned by ActiveRecord::Base.find
84
+ - Adds does_not_match suffix for regular expression based conditions, ie: :field_does_not_match => /regex/
85
+ - Adds not_between suffix for ange based conditions, ie: :id_not_between => ( 0 .. 1 )
86
+ - Adds SQLite and SQLite3 support for better finders.
87
+ - Updates rake tasks for sqlite and sqlite3.
88
+ - Added rake tasks to use database migrations rather then raw SQL schema files.
89
+
90
+ ActiveRecord::Extensions 0.1.0
91
+ -------------------------------
92
+ December 16th, 2006
93
+ - Adds to_csv method to arrays returned by ActiveRecord::Base.find.
94
+ - Fixes bug in ActiveRecord::Extensions::Registry when processing key/value pairs where
95
+ the order of certain Extensions was not handled correctly due to Hash usage.
96
+ - Refactoring of ActiveRecord::Extensions::Registry
97
+ - Added more tests for better finder support
98
+
99
+ ActiveRecord::Extensions 0.0.6
100
+ ------------------------------
101
+ December 5th, 2006
102
+ - Added generic support for import functionality for all adapters
103
+ - Includes rake testing tasks for postgresql
104
+ - Includes postgresql support for all extensions except for full text searching (which is only mysql)
105
+ - Refactored directory structure of tests, import functionality and fulltext functionality
106
+
107
+
108
+ ActiveRecord::Extensions 0.0.5
109
+ ------------------------------
110
+ October 20th, 2006.
111
+ - Fixes two bugs which broke normal ActiveRecord behavior
112
+ - Fully complaint with Rails 1.1.0 thru 1.1.6 (and all ActiveRecord versions released with those)
113
+ - Inlcudes new Rakefile
114
+ - Includes rake task "test:mysql" which allows ActiveRecord::Extensions to be tested with mysql
115
+ - Includes rake test "test:activerecord:mysql" which allows ActiveRecord's tests to be tested with the
116
+ ActiveRecord::Extensions library
117
+
118
+
119
+ ActiveRecord::Extensions 0.0.4
120
+ -------------------------------
121
+ August 26th, 2006. Released at RubyConf*MI.
122
+ September 24th, 2006, Rubyforge release.
123
+ - Inlcudes "Better Finder" support for ActiveRecord
124
+ http://blogs.mktec.com/zdennis/pages/ARE_finders
125
+
126
+
127
+ ActiveRecord::Extensions 0.0.3
128
+ -------------------------------
129
+ Released.... ????
130
+ - the project has been named ActiveRecord::Extensions.
131
+
132
+
133
+ ActiveRecord::Optimizations 0.0.2
134
+ ---------------------------------
135
+ July 20th, 11:27pm, Zach Dennis
136
+
137
+ This includes some of the optimizations for the ActiveRecord::Base. This release only supports the MysqlAdapter, although other adapters will be supported in upcoming releases.
138
+
139
+ HOW-TO USAGE
140
+ ------------
141
+ Require the two files in the lib/ directory and then create records using:
142
+ Model.create array_of_hashes
143
+
144
+ Example:
145
+ class LogEntry < ActiveRecord::Base ; end
146
+ LogEntry.import [ { :log_entry_name=>"Name" }, {:log_entry_name=>"Name2"}, ... ], :optimize=>true
147
+
148
+ Using the optimized create method will return the number of inserts performed, rather then an array of LogEntry objects. This currently skips model validation.
149
+
150
+
151
+ CHANGELOG
152
+ ----------
153
+ 0.0.2
154
+ - add some documentation to the updated methods for ActiveRecord and MysqlAdapter
155
+ - renamed the create optimizatin to import. Multi-value inserts can be obtained using ActiveRecord::Base.import
156
+ 0.0.1
157
+ - introduced updates to ActiveRecord::Base.create to support multi-value inserts
158
+
159
+
160
+ UPCOMING
161
+ ----------
162
+ - model validation on imports
163
+ - postgresql support for imports
164
+ - ability to use regular expressions for db searches
165
+ - ability to use db functions
166
+ - temporary table support
167
+ - memory table support
168
+ - complex update with on duplicate key update support
169
+
data/Rakefile ADDED
@@ -0,0 +1,61 @@
1
+ require "pathname"
2
+ require "rubygems"
3
+ require "rake"
4
+ require "rake/testtask"
5
+
6
+ DIR = Pathname.new(File.dirname(__FILE__))
7
+ ADAPTERS = %w(mysql postgresql sqlite sqlite3 oracle)
8
+
9
+ task :default => ["test:mysql"]
10
+
11
+ task :boot do
12
+ require DIR.join("lib", "ar-extensions").expand_path
13
+ require DIR.join("db", "migrate", "version").expand_path
14
+ end
15
+
16
+ ADAPTERS.each do |adapter|
17
+ namespace :db do
18
+ namespace :test do
19
+ desc "Builds test database for #{adapter}"
20
+ task "prepare_#{adapter}" do
21
+ ruby "#{DIR.join('tests', 'prepare.rb')} #{adapter}"
22
+ end
23
+ end
24
+ end
25
+
26
+ namespace :test do
27
+ desc "Test base extensions for #{adapter}"
28
+ task(adapter) do
29
+ ENV["ARE_DB"] = adapter
30
+ Rake::Task["db:test:prepare_#{adapter}"].invoke
31
+ ruby "#{DIR.join('tests', 'run.rb')} #{adapter}"
32
+ end
33
+ end
34
+
35
+ namespace :activerecord do
36
+ desc "Runs ActiveRecord unit tests for #{adapter} with ActiveRecord::Extensions"
37
+ task(adapter) do
38
+ activerecord_dir = ARGV[1]
39
+ if activerecord_dir.nil? || !File.directory?(activerecord_dir)
40
+ puts "ERROR: Pass in the path to ActiveRecord. Eg: /home/zdennis/rails_trunk/activerecord"
41
+ exit
42
+ end
43
+
44
+ old_dir, old_env = Dir.pwd, ENV["RUBYOPT"]
45
+ Dir.chdir(activerecord_dir)
46
+ ENV["RUBYOPT"] = "-r#{File.join(old_dir,'init.rb')}"
47
+
48
+ load "Rakefile"
49
+
50
+ Rake::Task["test_#{adapter}"].invoke
51
+ Dir.chdir(old_dir)
52
+ ENV["RUBYOPT"] = old_env
53
+ end
54
+
55
+ desc "Runs ActiveRecord unit tests for #{adapter} with ActiveRecord::Extensions with ALL available #{adapter} functionality"
56
+ task "#{adapter}_all" do
57
+ ENV["LOAD_ADAPTER_EXTENSIONS"] = adapter
58
+ Rake::Task["test:activerecord:#{adapter}"].invoke
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,7 @@
1
+ development:
2
+ adapter: mysql
3
+ database: aroptests
4
+ username: rails
5
+ password:
6
+ port: 3306
7
+ host: localhost
@@ -0,0 +1,7 @@
1
+ development:
2
+ adapter: mysql
3
+ database: aroptests
4
+ username: rails
5
+ password:
6
+ port: 3306
7
+ host: localhost
@@ -0,0 +1,72 @@
1
+
2
+ create table test_myisam(
3
+ id int(11) unsigned not null auto_increment,
4
+ my_name varchar(20) not null,
5
+ description varchar(255) default '',
6
+ primary key (id)
7
+ )ENGINE=MyISAM;
8
+
9
+
10
+ create table test_innodb(
11
+ id int(11) unsigned not null auto_increment,
12
+ my_name varchar(20) not null,
13
+ description varchar(255) default '',
14
+ primary key (id)
15
+ )ENGINE=InnoDb;
16
+
17
+
18
+ create table test_memory(
19
+ id int(11) unsigned not null auto_increment,
20
+ my_name varchar(20) not null,
21
+ description varchar(255) default '',
22
+ primary key (id)
23
+ )ENGINE=memory;
24
+
25
+
26
+ create temporary table test_temp(
27
+ id int(11) unsigned not null auto_increment,
28
+ my_name varchar(20) not null,
29
+ description varchar(255) default '',
30
+ primary key (id)
31
+ );
32
+
33
+ CREATE TABLE `topics` (
34
+ `id` int(11) NOT NULL auto_increment,
35
+ `title` varchar(255) default NULL,
36
+ `author_name` varchar(255) default NULL,
37
+ `author_email_address` varchar(255) default NULL,
38
+ `written_on` datetime default NULL,
39
+ `bonus_time` time default NULL,
40
+ `last_read` date default NULL,
41
+ `content` text,
42
+ `approved` tinyint(1) default '1',
43
+ `replies_count` int(11) default '0',
44
+ `parent_id` int(11) default NULL,
45
+ `type` varchar(50) default NULL,
46
+ PRIMARY KEY (`id`)
47
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
48
+
49
+ CREATE TABLE `projects` (
50
+ `id` int(11) NOT NULL auto_increment,
51
+ `name` varchar(100) default NULL,
52
+ `type` varchar(255) NOT NULL,
53
+ PRIMARY KEY (`id`)
54
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
55
+
56
+ CREATE TABLE `developers` (
57
+ `id` int(11) NOT NULL auto_increment,
58
+ `name` varchar(100) default NULL,
59
+ `salary` int(11) default '70000',
60
+ `created_at` datetime default NULL,
61
+ `updated_at` datetime default NULL,
62
+ PRIMARY KEY (`id`)
63
+ ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
64
+
65
+ CREATE TABLE `books` (
66
+ `id` int(11) NOT NULL auto_increment,
67
+ `title` varchar(255) NOT NULL,
68
+ `publisher` varchar(255) NOT NULL,
69
+ `author_name` varchar(255) NOT NULL,
70
+ PRIMARY KEY (`id`),
71
+ FULLTEXT( `title`, `publisher`, `author_name` )
72
+ ) ENGINE=MyISAM;
@@ -0,0 +1,39 @@
1
+ CREATE TABLE topics (
2
+ id serial NOT NULL,
3
+ title character varying(255) default NULL,
4
+ author_name character varying(255) default NULL,
5
+ author_email_address character varying(255) default NULL,
6
+ written_on timestamp default NULL,
7
+ bonus_time time default NULL,
8
+ last_read date default NULL,
9
+ content text,
10
+ approved bool default TRUE,
11
+ replies_count integer default 0,
12
+ parent_id serial default NULL,
13
+ type character varying(50) default NULL,
14
+ PRIMARY KEY (id)
15
+ );
16
+
17
+ CREATE TABLE projects (
18
+ id serial NOT NULL,
19
+ name character varying(100) default NULL,
20
+ type character varying(255) NOT NULL,
21
+ PRIMARY KEY (id)
22
+ );
23
+
24
+ CREATE TABLE developers (
25
+ id serial NOT NULL,
26
+ name character varying(100) default NULL,
27
+ salary integer default 70000,
28
+ created_at timestamp default NULL,
29
+ updated_at timestamp default NULL,
30
+ PRIMARY KEY (id)
31
+ );
32
+
33
+ CREATE TABLE books (
34
+ id serial NOT NULL,
35
+ title character varying(255) NOT NULL,
36
+ publisher character varying(255) NOT NULL,
37
+ author_name character varying(255) NOT NULL,
38
+ PRIMARY KEY (id)
39
+ );
@@ -0,0 +1,97 @@
1
+ ActiveRecord::Schema.define do
2
+
3
+ create_table :schema_info, :force=>true do |t|
4
+ t.column :version, :integer, :unique=>true
5
+ end
6
+ SchemaInfo.create :version=>SchemaInfo::VERSION
7
+
8
+ create_table :group, :force => true do |t|
9
+ t.column :order, :string
10
+ t.timestamps
11
+ end
12
+
13
+ create_table :topics, :force=>true do |t|
14
+ t.column :title, :string, :null=>false
15
+ t.column :author_name, :string
16
+ t.column :author_email_address, :string
17
+ t.column :written_on, :datetime
18
+ t.column :bonus_time, :time
19
+ t.column :last_read, :datetime
20
+ t.column :content, :text
21
+ t.column :approved, :boolean, :default=>'1'
22
+ t.column :replies_count, :integer
23
+ t.column :parent_id, :integer
24
+ t.column :type, :string
25
+ t.column :created_at, :datetime
26
+ t.column :updated_at, :datetime
27
+ end
28
+
29
+ create_table :projects, :force=>true do |t|
30
+ t.column :name, :string
31
+ t.column :type, :string
32
+ end
33
+
34
+ create_table :developers, :force=>true do |t|
35
+ t.column :name, :string
36
+ t.column :salary, :integer, :default=>'70000'
37
+ t.column :created_at, :datetime
38
+ t.column :team_id, :integer
39
+ t.column :updated_at, :datetime
40
+ end
41
+
42
+ create_table :addresses, :force=>true do |t|
43
+ t.column :address, :string
44
+ t.column :city, :string
45
+ t.column :state, :string
46
+ t.column :zip, :string
47
+ t.column :developer_id, :integer
48
+ end
49
+
50
+ create_table :teams, :force=>true do |t|
51
+ t.column :name, :string
52
+ end
53
+
54
+ create_table :books, :force=>true do |t|
55
+ t.column :title, :string, :null=>false
56
+ t.column :publisher, :string, :null=>false, :default => 'Default Publisher'
57
+ t.column :author_name, :string, :null=>false
58
+ t.column :created_at, :datetime
59
+ t.column :created_on, :datetime
60
+ t.column :updated_at, :datetime
61
+ t.column :updated_on, :datetime
62
+ t.column :publish_date, :date
63
+ t.column :topic_id, :integer
64
+ t.column :for_sale, :boolean, :default => true
65
+ end
66
+
67
+ create_table :languages, :force=>true do |t|
68
+ t.column :name, :string
69
+ t.column :developer_id, :integer
70
+ end
71
+
72
+ create_table :shopping_carts, :force=>true do |t|
73
+ t.column :name, :string, :null => true
74
+ t.column :created_at, :datetime
75
+ t.column :updated_at, :datetime
76
+ end
77
+
78
+ create_table :cart_items, :force => true do |t|
79
+ t.column :shopping_cart_id, :string, :null => false
80
+ t.column :book_id, :string, :null => false
81
+ t.column :copies, :integer, :default => 1
82
+ t.column :created_at, :datetime
83
+ t.column :updated_at, :datetime
84
+ end
85
+
86
+ add_index :cart_items, [:shopping_cart_id, :book_id], :unique => true, :name => 'uk_shopping_cart_books'
87
+
88
+ create_table :animals, :force => true do |t|
89
+ t.column :name, :string, :null => false
90
+ t.column :size, :string, :default => nil
91
+ t.column :created_at, :datetime
92
+ t.column :updated_at, :datetime
93
+ end
94
+
95
+ add_index :animals, [:name], :unique => true, :name => 'uk_animals'
96
+
97
+ end
@@ -0,0 +1,32 @@
1
+ ActiveRecord::Schema.define do
2
+
3
+ create_table :test_myisam, :options=>'ENGINE=MyISAM', :force=>true do |t|
4
+ t.column :my_name, :string, :null=>false
5
+ t.column :description, :string
6
+ end
7
+
8
+ create_table :test_innodb, :options=>'ENGINE=InnoDb', :force=>true do |t|
9
+ t.column :my_name, :string, :null=>false
10
+ t.column :description, :string
11
+ end
12
+
13
+ create_table :test_memory, :options=>'ENGINE=Memory', :force=>true do |t|
14
+ t.column :my_name, :string, :null=>false
15
+ t.column :description, :string
16
+ end
17
+
18
+ create_table :books, :options=>'ENGINE=MyISAM', :force=>true do |t|
19
+ t.column :title, :string, :null=>false
20
+ t.column :publisher, :string, :null=>false, :default => 'Default Publisher'
21
+ t.column :author_name, :string, :null=>false
22
+ t.column :created_at, :datetime
23
+ t.column :created_on, :datetime
24
+ t.column :updated_at, :datetime
25
+ t.column :updated_on, :datetime
26
+ t.column :publish_date, :date
27
+ t.column :topic_id, :integer
28
+ t.column :for_sale, :boolean, :default => true
29
+ end
30
+ execute "ALTER TABLE books ADD FULLTEXT( `title`, `publisher`, `author_name` )"
31
+
32
+ end
@@ -0,0 +1,5 @@
1
+ ActiveRecord::Schema.define do
2
+
3
+ execute "CREATE SEQUENCE books_seq START_WITH 1"
4
+
5
+ end
@@ -0,0 +1,4 @@
1
+ class SchemaInfo < ActiveRecord::Base
2
+ set_table_name 'schema_info'
3
+ VERSION = 12
4
+ end
data/init.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'ostruct'
2
+ begin ; require 'active_record' ; rescue LoadError; require 'rubygems'; require 'active_record'; end
3
+
4
+ $LOAD_PATH.unshift File.expand_path(File.join(File.dirname(__FILE__), 'lib'))
5
+
6
+ require 'ar-extensions/util/support_methods'
7
+ require 'ar-extensions/util/sql_generation'
8
+ require 'ar-extensions/version'
9
+ require 'ar-extensions/delete'
10
+ require 'ar-extensions/extensions'
11
+ require 'ar-extensions/create_and_update'
12
+ require 'ar-extensions/finder_options'
13
+ require 'ar-extensions/foreign_keys'
14
+ require 'ar-extensions/fulltext'
15
+ require 'ar-extensions/import'
16
+ require 'ar-extensions/insert_select'
17
+ require 'ar-extensions/finders'
18
+ require 'ar-extensions/synchronize'
19
+ require 'ar-extensions/temporary_table'
20
+ require 'ar-extensions/union'
21
+ require 'ar-extensions/adapters/abstract_adapter'
22
+
23
+ #load all available functionality for specified adapter
24
+ # Ex. ENV['LOAD_ADAPTER_EXTENSIONS'] = 'mysql'
25
+ if ENV['LOAD_ADAPTER_EXTENSIONS']
26
+ require "active_record/connection_adapters/#{ENV['LOAD_ADAPTER_EXTENSIONS']}_adapter.rb"
27
+ file_regexp = File.join(File.dirname(__FILE__), 'lib', 'ar-extensions','**',
28
+ "#{ENV['LOAD_ADAPTER_EXTENSIONS']}.rb")
29
+
30
+ Dir.glob(file_regexp){|file| require(file) }
31
+ end