bigrecord 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (104) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +44 -0
  3. data/Rakefile +17 -0
  4. data/VERSION +1 -0
  5. data/doc/bigrecord_specs.rdoc +36 -0
  6. data/doc/getting_started.rdoc +157 -0
  7. data/examples/bigrecord.yml +25 -0
  8. data/generators/bigrecord/bigrecord_generator.rb +17 -0
  9. data/generators/bigrecord/templates/bigrecord.rake +47 -0
  10. data/generators/bigrecord_migration/bigrecord_migration_generator.rb +13 -0
  11. data/generators/bigrecord_migration/templates/migration.rb +9 -0
  12. data/generators/bigrecord_model/bigrecord_model_generator.rb +28 -0
  13. data/generators/bigrecord_model/templates/migration.rb +13 -0
  14. data/generators/bigrecord_model/templates/model.rb +7 -0
  15. data/generators/bigrecord_model/templates/model_spec.rb +12 -0
  16. data/init.rb +9 -0
  17. data/install.rb +22 -0
  18. data/lib/big_record/abstract_base.rb +1088 -0
  19. data/lib/big_record/action_view_extensions.rb +266 -0
  20. data/lib/big_record/ar_associations/association_collection.rb +194 -0
  21. data/lib/big_record/ar_associations/association_proxy.rb +158 -0
  22. data/lib/big_record/ar_associations/belongs_to_association.rb +57 -0
  23. data/lib/big_record/ar_associations/belongs_to_many_association.rb +57 -0
  24. data/lib/big_record/ar_associations/has_and_belongs_to_many_association.rb +164 -0
  25. data/lib/big_record/ar_associations/has_many_association.rb +191 -0
  26. data/lib/big_record/ar_associations/has_one_association.rb +80 -0
  27. data/lib/big_record/ar_associations.rb +1608 -0
  28. data/lib/big_record/ar_reflection.rb +223 -0
  29. data/lib/big_record/attribute_methods.rb +75 -0
  30. data/lib/big_record/base.rb +618 -0
  31. data/lib/big_record/br_associations/association_collection.rb +194 -0
  32. data/lib/big_record/br_associations/association_proxy.rb +153 -0
  33. data/lib/big_record/br_associations/belongs_to_association.rb +52 -0
  34. data/lib/big_record/br_associations/belongs_to_many_association.rb +293 -0
  35. data/lib/big_record/br_associations/cached_item_proxy.rb +194 -0
  36. data/lib/big_record/br_associations/cached_item_proxy_factory.rb +62 -0
  37. data/lib/big_record/br_associations/has_and_belongs_to_many_association.rb +168 -0
  38. data/lib/big_record/br_associations/has_one_association.rb +80 -0
  39. data/lib/big_record/br_associations.rb +978 -0
  40. data/lib/big_record/br_reflection.rb +151 -0
  41. data/lib/big_record/callbacks.rb +367 -0
  42. data/lib/big_record/connection_adapters/abstract/connection_specification.rb +279 -0
  43. data/lib/big_record/connection_adapters/abstract/database_statements.rb +175 -0
  44. data/lib/big_record/connection_adapters/abstract/quoting.rb +58 -0
  45. data/lib/big_record/connection_adapters/abstract_adapter.rb +190 -0
  46. data/lib/big_record/connection_adapters/column.rb +491 -0
  47. data/lib/big_record/connection_adapters/hbase_adapter.rb +432 -0
  48. data/lib/big_record/connection_adapters/view.rb +27 -0
  49. data/lib/big_record/connection_adapters.rb +10 -0
  50. data/lib/big_record/deletion.rb +73 -0
  51. data/lib/big_record/dynamic_schema.rb +92 -0
  52. data/lib/big_record/embedded.rb +71 -0
  53. data/lib/big_record/embedded_associations/association_proxy.rb +148 -0
  54. data/lib/big_record/family_span_columns.rb +89 -0
  55. data/lib/big_record/fixtures.rb +1025 -0
  56. data/lib/big_record/migration.rb +380 -0
  57. data/lib/big_record/routing_ext.rb +65 -0
  58. data/lib/big_record/timestamp.rb +51 -0
  59. data/lib/big_record/validations.rb +830 -0
  60. data/lib/big_record.rb +125 -0
  61. data/lib/bigrecord.rb +1 -0
  62. data/rails/init.rb +9 -0
  63. data/spec/connections/bigrecord.yml +13 -0
  64. data/spec/connections/cassandra/connection.rb +2 -0
  65. data/spec/connections/hbase/connection.rb +2 -0
  66. data/spec/debug.log +281 -0
  67. data/spec/integration/br_associations_spec.rb +80 -0
  68. data/spec/lib/animal.rb +12 -0
  69. data/spec/lib/book.rb +10 -0
  70. data/spec/lib/broken_migrations/duplicate_name/20090706182535_add_animals_table.rb +14 -0
  71. data/spec/lib/broken_migrations/duplicate_name/20090706193019_add_animals_table.rb +9 -0
  72. data/spec/lib/broken_migrations/duplicate_version/20090706190623_add_books_table.rb +9 -0
  73. data/spec/lib/broken_migrations/duplicate_version/20090706190623_add_companies_table.rb +9 -0
  74. data/spec/lib/company.rb +14 -0
  75. data/spec/lib/embedded/web_link.rb +12 -0
  76. data/spec/lib/employee.rb +33 -0
  77. data/spec/lib/migrations/20090706182535_add_animals_table.rb +13 -0
  78. data/spec/lib/migrations/20090706190623_add_books_table.rb +15 -0
  79. data/spec/lib/migrations/20090706193019_add_companies_table.rb +14 -0
  80. data/spec/lib/migrations/20090706194512_add_employees_table.rb +13 -0
  81. data/spec/lib/migrations/20090706195741_add_zoos_table.rb +13 -0
  82. data/spec/lib/novel.rb +5 -0
  83. data/spec/lib/zoo.rb +17 -0
  84. data/spec/spec.opts +4 -0
  85. data/spec/spec_helper.rb +55 -0
  86. data/spec/unit/abstract_base_spec.rb +287 -0
  87. data/spec/unit/adapters/abstract_adapter_spec.rb +56 -0
  88. data/spec/unit/adapters/adapter_shared_spec.rb +51 -0
  89. data/spec/unit/adapters/hbase_adapter_spec.rb +15 -0
  90. data/spec/unit/ar_associations_spec.rb +8 -0
  91. data/spec/unit/base_spec.rb +6 -0
  92. data/spec/unit/br_associations_spec.rb +58 -0
  93. data/spec/unit/embedded_spec.rb +43 -0
  94. data/spec/unit/find_spec.rb +34 -0
  95. data/spec/unit/hash_helper_spec.rb +44 -0
  96. data/spec/unit/migration_spec.rb +144 -0
  97. data/spec/unit/model_spec.rb +315 -0
  98. data/spec/unit/validations_spec.rb +182 -0
  99. data/tasks/bigrecord_tasks.rake +47 -0
  100. data/tasks/data_store.rb +46 -0
  101. data/tasks/gem.rb +22 -0
  102. data/tasks/rdoc.rb +8 -0
  103. data/tasks/spec.rb +34 -0
  104. metadata +189 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 openplaces
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,44 @@
1
+ = Big Record
2
+
3
+ A Ruby Object/Data Mapper for distributed column-oriented data stores (inspired by BigTable) such as HBase. Intended to work as a drop-in for Rails applications. More information soon...
4
+
5
+ == Features
6
+ * Dynamic schemas (due to the schema-less design of BigTable).
7
+ * Support for column-oriented data stores.
8
+ * Similar usage to Active Record.
9
+ * Embedded records that store within a single table row.
10
+ * Automatic versioning.
11
+ * Scalability (depending on the data store used).
12
+
13
+ == Why would I use it?
14
+
15
+ BigTable, and by extension, Big Record isn't right for everyone. A great introductory article discussing this topic can be found at http://blog.rapleaf.com/dev/?p=26 explaining why you would or wouldn't use BigTable. The rule of thumb, however, is that if your data model is simple or can fit into a standard RDBMS, then you probably don't need it.
16
+
17
+ Beyond this though, there are two basic motivations that almost immediately demand a BigTable model database:
18
+ 1. Your data is highly dynamic in nature and would not fit in a schema bound model, or you cannot define a schema ahead of time.
19
+ 2. You know that your database will grow to tens or hundreds of gigabytes, and can't afford big iron servers. Instead, you'd like to scale horizontally across many commodity servers.
20
+
21
+ == Requirements
22
+
23
+ * Big Record: Ruby Object/Data Mapper. Inspired and architected similarly to Active Record.
24
+ * Big Record Driver: JRuby application that bridges Ruby and Java (through JRuby's Drb protocol) to interact with Java-based data stores and their native APIs. Required for HBase and Cassandra. This application can be run from a separate server than your Rails application.
25
+ * JRuby 1.1.6+ is needed to run Big Record Driver.
26
+ * Any other requirements needed to run Hadoop, HBase or your data store of choice.
27
+
28
+ == Optional Requirements
29
+
30
+ * Big Index (highly recommended): Due to the nature of Big Table data stores, some limitations occur while using Big Record standalone when compared to Active Record. Some major limitations include the inability to query for data other than with the row ID, indexing, searching, and dynamic finders (find_by_attribute_name). Since these data access patterns are vital for most Rails applications to function, Big Index was created to address these issues, and bring the feature set more up to par with Active Record. Please refer to the <tt>Big Index</tt> package for more information and its requirements.
31
+
32
+ == Getting Started
33
+
34
+ Check out the doc/getting_started.rdoc file for more information.
35
+
36
+ == License
37
+
38
+ Big Record is released under the MIT license.
39
+
40
+ == Links
41
+
42
+ * Contact Us
43
+ * Website - http://www.bigrecord.org
44
+ * IRC Channel - <tt>#bigrecord</tt> on irc.freenode.net
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'rake/rdoctask'
6
+ require 'rake/gempackagetask'
7
+ require 'pathname'
8
+ require 'spec/rake/spectask'
9
+
10
+
11
+ DATA_STORES = ["hbase", "cassandra"]
12
+ ROOT = Pathname(__FILE__).dirname.expand_path
13
+
14
+ require ROOT + 'tasks/gem'
15
+ require ROOT + 'tasks/rdoc'
16
+ require ROOT + 'tasks/spec'
17
+ require ROOT + 'tasks/data_store'
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.5
@@ -0,0 +1,36 @@
1
+ = Bigrecord Specs
2
+
3
+ == Data store information
4
+
5
+ The default settings for the Bigrecord specs can be found at spec/connections/bigrecord.yml with each environment broken down by the data store type (Hbase and Cassandra at the time of writing). These are the minimal settings required to connect to each data store, and should be modified freely to reflect your own system configurations.
6
+
7
+ == Data store migration
8
+
9
+ There are also migrations to create the necessary tables for the specs to run. To ensure migrations are functioning properly before actually running the migrations, you can run: spec spec/unit/migration_spec.rb. Alternatively, you can manually create the tables according to the migration files under: spec/lib/migrations
10
+
11
+ Migrations have their own log file for debugging purposes. It's created under: bigrecord/migrate.log
12
+
13
+ == Running the specs
14
+
15
+ After setting it up, you can run the Bigrecord specs with:
16
+
17
+ rake spec
18
+
19
+ or alternatively, with either:
20
+
21
+ rake spec:hbase
22
+ rake spec:cassandra
23
+
24
+ if you want to run the spec suite against a specific data store.
25
+
26
+ == Running specific specs
27
+
28
+ To run a specific spec, you can run the following command from the bigrecord root folder:
29
+
30
+ spec -O spec/spec.opts spec/<spec_file>_spec.rb
31
+
32
+ == Debugging
33
+
34
+ If any problems or failures arise during the unit tests, please refer to the log files before submitting it as an issue. Often, it's a simple matter of forgetting to turn on BigrecordDriver, the tables weren't created, or configurations weren't set properly.
35
+
36
+ The log file for specs is created under: <bigrecord root>/spec/debug.log
@@ -0,0 +1,157 @@
1
+ = Getting Started
2
+
3
+ == Requirements
4
+
5
+ * Database set up (please refer to the database's own documentation) with the required information known such as host, port, username, password, etc. in order for Bigrecord to connect to it.
6
+ * Bigrecord Driver (if your database requires it for connecting)
7
+ * JRuby 1.1.6+ is needed to run Bigrecord Driver.
8
+
9
+ == *NOTE* At the time of this writing, Hbase is the only supported database for Bigrecord, and the following instructions are for specific to Hbase.
10
+
11
+ == Installation
12
+
13
+ (1) Install the Bigrecord Driver gem and its dependencies, then start up a DRb server. Please see the Bigrecord Driver documentation for more detailed instructions. (http://github.com/openplaces/bigrecord/blob/master/bigrecord-driver/README.rdoc)
14
+
15
+ === Method 1 (recommended): Install as a gem
16
+
17
+ (2) Add the following line into the Rails::Initializer.run do |config| block:
18
+
19
+ config.gem "bigrecord", :source => "http://gemcutter.org"
20
+
21
+ (3) Bootstrap Bigrecord into your project:
22
+
23
+ script/generate bigrecord
24
+
25
+ (4) Edit the config/bigrecord.yml[.sample] file in your Rails root to the information corresponding to your database install and Bigrecord Driver DRb server.
26
+
27
+ === Method 2: Install as a plugin
28
+
29
+ (2) Run the following command to install it as a plugin:
30
+
31
+ script/plugin install git://github.com/openplaces/bigrecord.git
32
+
33
+ (3) Edit the config/bigrecord.yml[.sample] file in your Rails root to the information corresponding to your database install and Bigrecord Driver DRb server.
34
+
35
+ == Usage
36
+
37
+ === Generators
38
+
39
+ Once Bigrecord is working in your Rails project, you can use the following generators:
40
+
41
+ script/generate bigrecord_model ModelName
42
+
43
+ This will add a model in app/models and a migration file in db/bigrecord_migrate. Note: This generator does not accept attributes.
44
+
45
+ script/generate bigrecord_migration MigrationName
46
+
47
+ Creates a Bigrecord specific migration and adds it into db/bigrecord_migrate
48
+
49
+ === Migration File
50
+
51
+ Although column-oriented databases are generally schema-less, certain ones (like Hbase) require the creation of tables and column families ahead of time. The individual columns, however, are defined in the model itself and can be modified dynamically without the need for migrations.
52
+
53
+ Unless you're familiar with column families, the majority of use cases work perfectly fine within one column family. When you generate a bigrecord_model, it will default to creating the :attribute column family.
54
+
55
+ The following is a standard migration file that creates a table called "Books" with the default column family :attribute that has the following option of 100 versions and uses the 'lzo' compression scheme. Leave any options blank for the default value.
56
+
57
+ class CreateBooks < BigRecord::Migration
58
+ def self.up
59
+ create_table :books, :force => true do |t|
60
+ t.family :attribute, :versions => 100, :compression => 'lzo'
61
+ end
62
+ end
63
+
64
+ def self.down
65
+ drop_table :books
66
+ end
67
+ end
68
+
69
+ === HBase column family options (HBase specific)
70
+
71
+ * versions: integer. By default, Hbase will store 3 versions of changes for any column family. Changing this value on the creation will change this behavior.
72
+ * compression: 'none', 'gz', 'lzo'. Defaults to 'none'. Since Hbase 0.20, column families can be stored using compression. The compression scheme you define here must be installed on the Hbase servers!
73
+
74
+ === Migrating
75
+
76
+ Run the following rake task to migrate your tables and column families up to the latest version:
77
+
78
+ rake bigrecord:migrate
79
+
80
+ === Column and Attribute Definition
81
+
82
+ Now that you have your tables and column families all set up, you can begin adding columns to your model. The following is an example of a model named book.rb
83
+
84
+ class Book < BigRecord::Base
85
+ column 'attribute:title', :string
86
+ column :author, :string
87
+ column :description, :string
88
+ column :links, :string, :collection => true
89
+ end
90
+
91
+ This simple model defines 4 columns of type string. An important thing to notice here is that the first column 'attribute:title' had the column family prepended to it. This is identical to just passing the symbol :title to the column method, and the default behaviour is to prepend the column family (attribute) automatically if one is not defined. Furthermore, in Hbase, there's the option of storing collections for a given column. This will return an array for the links attribute on a Book record.
92
+
93
+ === Associations
94
+
95
+ There are also associations available in Bigrecord, as well as the ability to associate to Activerecord models. The following are a few models demonstrating this:
96
+
97
+ animal.rb
98
+ class Animal < BigRecord::Base
99
+ # Typical attributes
100
+ column :name, :string
101
+ column :type, :integer
102
+ column :description, :string
103
+
104
+ # Association attributes
105
+ column :zoo_id, :string
106
+ column :trainer_id, :integer
107
+
108
+ # Associations
109
+ belongs_to_big_record :zoo, :foreign_key => :zoo_id
110
+ belongs_to :trainer, :foreign_key => :trainer_id
111
+ end
112
+
113
+ In this example, an Animal is related to Zoo and Trainer. Both Animal and Zoo are Bigrecord models, and Trainer is an Activerecord model. Notice here that we need to define both the association field for storing the information and the association itself. It's also important to remember that Bigrecord models have their IDs stored as string, and Activerecord models use integers.
114
+
115
+ Once the association columns are defined, you define the associations themselves with either belongs_to_bigrecord or belongs_to_many and defining the :foreign_key (this is required for all associations).
116
+
117
+ === Specifying return columns
118
+
119
+ There are two ways to define specific columns to be returned with your models: 1) at the model level and 2) during the query.
120
+
121
+ (1) At the model level, a collection of columns are called named views, and are defined like the following:
122
+
123
+ class Book < BigRecord::Base
124
+ column :title, :string
125
+ column :author, :string
126
+ column :description, :string
127
+ column :links, :string, :collection => true
128
+
129
+ view :front_page, :title, :author
130
+ view :summary_page, :title, :author, :description
131
+
132
+ # Override default if you don't want all columns returend
133
+ view :default, :title, :author, :description
134
+ end
135
+
136
+ Now, whenever you work with a Book record, it will only returned the columns you specify according to the view option you pass. i.e.
137
+
138
+ >> Book.find(:first, :view => :front_page)
139
+ => #<Book id: "2e13f182-1085-495e-9841-fe5c84ae9992", attribute:title: "Hello Thar", attribute:author: "Greg">
140
+
141
+ >> Book.find(:first, :view => :summary_page)
142
+ => #<Book id: "2e13f182-1085-495e-9841-fe5c84ae9992", attribute:description: "Masterpiece!", attribute:title: "Hello Thar", attribute:author: "Greg">
143
+
144
+ >> Book.find(:first, :view => :default)
145
+ => #<Book id: "2e13f182-1085-495e-9841-fe5c84ae9992", attribute:description: "Masterpiece!", attribute:title: "Hello Thar", attribute:links: ["link1", "link2", "link3", "link4"], attribute:author: "Greg">
146
+
147
+ Note: A Bigrecord model will return all the columns within the default column family (when :view option is left blank, for example). You can override the :default name view to change this behaviour.
148
+
149
+
150
+ (2) If you don't want to define named views ahead of time, you can just pass an array of columns to the :columns option and it will return only those attributes:
151
+
152
+ >> Book.find(:first, :columns => [:author, :description])
153
+ => #<Book id: "2e13f182-1085-495e-9841-fe5c84ae9992", attribute:description: "Masterpiece!", attribute:author: "Greg">
154
+
155
+ As you may have noticed, this functionality is synonymous with the :select option in Activerecord.
156
+
157
+ === At this point, usage patterns for a Bigrecord model are similar to that of an Activerecord model, and much of that documentation applies as well. Please refer to those and see if they work!
@@ -0,0 +1,25 @@
1
+ development:
2
+ adapter: hbase
3
+ zookeeper_quorum: localhost
4
+ zookeeper_client_port: 2181
5
+ drb_host: localhost
6
+ drb_port: 40000
7
+ test:
8
+ adapter: hbase
9
+ zookeeper_quorum: localhost
10
+ zookeeper_client_port: 2182
11
+ drb_host: localhost
12
+ drb_port: 40001
13
+ production:
14
+ adapter: hbase
15
+ zookeeper_quorum: localhost
16
+ zookeeper_client_port: 2183
17
+ drb_host: localhost
18
+ drb_port: 40002
19
+
20
+ cassandra:
21
+ adapter: cassandra
22
+ address: localhost
23
+ port: 9160
24
+ drb_host: localhost
25
+ drb_port: 40003
@@ -0,0 +1,17 @@
1
+ # This generator bootstraps a Rails project for use with Bigrecord
2
+ class BigrecordGenerator < Rails::Generator::Base
3
+
4
+ def initialize(runtime_args, runtime_options = {})
5
+ require File.join(File.dirname(__FILE__), "..", "..", "install.rb")
6
+ Dir.mkdir('lib/tasks') unless File.directory?('lib/tasks')
7
+ super
8
+ end
9
+
10
+ def manifest
11
+ record do |m|
12
+ m.directory 'lib/tasks'
13
+ m.file 'bigrecord.rake', 'lib/tasks/bigrecord.rake'
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,47 @@
1
+ namespace :bigrecord do
2
+
3
+ desc "Migrate the Bigrecord database through scripts in db/bigrecord_migrate. Target specific version with VERSION=x. Turn off output with VERBOSE=false."
4
+ task :migrate => :environment do
5
+ BigRecord::Migrator.migrate("db/bigrecord_migrate/", ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
6
+ end
7
+
8
+ namespace :migrate do
9
+ desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x. Target specific version with VERSION=x.'
10
+ task :redo => :environment do
11
+ if ENV["VERSION"]
12
+ Rake::Task["bigrecord:migrate:down"].invoke
13
+ Rake::Task["bigrecord:migrate:up"].invoke
14
+ else
15
+ Rake::Task["bigrecord:rollback"].invoke
16
+ Rake::Task["bigrecord:migrate"].invoke
17
+ end
18
+ end
19
+
20
+ desc 'Runs the "up" for a given migration VERSION.'
21
+ task :up => :environment do
22
+ version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
23
+ raise "VERSION is required" unless version
24
+ BigRecord::Migrator.run(:up, "db/bigrecord_migrate/", version)
25
+ end
26
+
27
+ desc 'Runs the "down" for a given migration VERSION.'
28
+ task :down => :environment do
29
+ version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
30
+ raise "VERSION is required" unless version
31
+ BigRecord::Migrator.run(:up, "db/bigrecord_migrate/", version)
32
+ end
33
+ end
34
+
35
+ desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'
36
+ task :rollback => :environment do
37
+ step = ENV['STEP'] ? ENV['STEP'].to_i : 1
38
+ BigRecord::Migrator.rollback('db/bigrecord_migrate/', step)
39
+ end
40
+
41
+ desc 'Pushes the schema to the next version. Specify the number of steps with STEP=n'
42
+ task :forward => :environment do
43
+ step = ENV['STEP'] ? ENV['STEP'].to_i : 1
44
+ BigRecord::Migrator.forward('db/bigrecord_migrate/', step)
45
+ end
46
+
47
+ end
@@ -0,0 +1,13 @@
1
+ require 'rails_generator/generators/components/migration/migration_generator'
2
+
3
+ class BigrecordMigrationGenerator < MigrationGenerator
4
+
5
+ def manifest
6
+
7
+ record do |m|
8
+ m.migration_template 'migration.rb', 'db/bigrecord_migrate', :assigns => get_local_assigns
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,9 @@
1
+ class <%= class_name.underscore.camelize %> < BigRecord::Migration
2
+
3
+ def self.up
4
+ end
5
+
6
+ def self.down
7
+ end
8
+
9
+ end
@@ -0,0 +1,28 @@
1
+ require 'rails_generator/generators/components/model/model_generator'
2
+
3
+ class BigrecordModelGenerator < ModelGenerator
4
+
5
+ def manifest
6
+
7
+ record do |m|
8
+ # Check for class naming collisions.
9
+ m.class_collisions class_path, class_name
10
+
11
+ # Model, spec, and fixture directories.
12
+ m.directory File.join('app/models', class_path)
13
+ m.directory File.join('spec/models', class_path)
14
+
15
+ # Model class, spec and fixtures.
16
+ m.template 'model.rb', File.join('app/models', class_path, "#{file_name}.rb")
17
+ m.template 'model_spec.rb', File.join('spec/models', class_path, "#{file_name}_spec.rb")
18
+
19
+ unless options[:skip_migration]
20
+ m.migration_template 'migration.rb', 'db/bigrecord_migrate', :assigns => {
21
+ :migration_name => "Create#{class_name.pluralize.gsub(/::/, '')}"
22
+ }, :migration_file_name => "create_#{file_path.gsub(/\//, '_').pluralize}"
23
+ end
24
+ end
25
+
26
+ end
27
+
28
+ end
@@ -0,0 +1,13 @@
1
+ class <%= migration_name %> < BigRecord::Migration
2
+
3
+ def self.up
4
+ create_table :<%= table_name %>, :force => true do |t|
5
+ t.family :attribute
6
+ end
7
+ end
8
+
9
+ def self.down
10
+ drop_table :<%= table_name %>
11
+ end
12
+
13
+ end
@@ -0,0 +1,7 @@
1
+ class <%= class_name %> < BigRecord::Base
2
+
3
+ <% attributes.each do |attribute| -%>
4
+ column :<%= attribute.name %>,<%= " " * (20 - attribute.name.length) %>:<%= attribute.type %>
5
+ <% end -%>
6
+
7
+ end
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../spec_helper')
2
+
3
+ describe <%= class_name %> do
4
+ before(:each) do
5
+ @valid_attributes = {
6
+ }
7
+ end
8
+
9
+ it "should create a new instance given valid attributes" do
10
+ <%= class_name %>.create!(@valid_attributes)
11
+ end
12
+ end
data/init.rb ADDED
@@ -0,0 +1,9 @@
1
+ require 'big_record'
2
+
3
+ # Use the same logger as ActiveRecord to make sure that the access to the log file is properly handled
4
+ BigRecord::Base.logger = ActiveRecord::Base.logger
5
+ BigRecord::Embedded.logger = ActiveRecord::Base.logger
6
+
7
+ # Establish the connection with the database
8
+ BigRecord::Base.configurations = YAML::load(File.open("#{RAILS_ROOT}/config/bigrecord.yml"))
9
+ BigRecord::Base.establish_connection
data/install.rb ADDED
@@ -0,0 +1,22 @@
1
+ require 'fileutils'
2
+
3
+ puts "[Bigrecord] Copying example config file to your RAILS_ROOT...\n"
4
+
5
+ config_dir = File.join(RAILS_ROOT, "config")
6
+ source = File.join(File.dirname(__FILE__), "examples", "bigrecord.yml")
7
+ target = File.join(config_dir, "bigrecord.yml")
8
+ alternate_target = File.join(config_dir, "bigrecord.yml.sample")
9
+
10
+ migration_dir = File.join(RAILS_ROOT, "db", "bigrecord_migrate")
11
+
12
+ if !File.exist?(target)
13
+ FileUtils.cp(source, target)
14
+ else
15
+ puts "[Bigrecord] RAILS_ROOT/config/bigrecord.yml file already exists. Copying it as bigrecord.yml.sample for reference."
16
+ FileUtils.cp(source, alternate_target)
17
+ end
18
+
19
+ unless File.exist?(migration_dir)
20
+ puts "[Bigrecord] Migration folder not found at \"#{migration_dir}\" Creating now..."
21
+ FileUtils.mkdir_p(migration_dir)
22
+ end