Camping Gear to bring ActiveRecord to your Camping app.
Install using bundler:
bundle add guidebook
Guidebook should now be added as a Gemfile dependency and gem installed. So you can navigate to your Camping app and install it there too. Run this in your shell:
guidebook install
This will generate a db/
directory, along with a db/config.kdl
, and a db/migrate
folder for your migrations. If you have a Rakefile, it will append Code to install database commands to your Rakefile.
You'll need to pack guidebook to get it working in your app:
require 'camping'
require 'guidebook'
Camping.goes :MyApp
module MyApp
pack Camping::GuideBook
module Models
class Page < Base; end
end
# you'll need to connect to your database in the #create method
def self.create
establish_connection()
end
end
When you pack guidebook
into your camping app, guidebook adds an #establish_connection
method to your camping app. Call this in your #create
method to connect to your database.
module MyApp
module Models class Page < Base; end end
def self.create
establish_connection()
end
end
Just do it!
Running guidebook install
should add migration support to your Rakefile.
To make a new migration run this in your terminal:
rake db:new_migration name=MyNewMigration
Which should produce:
class MyNewMigration < ActiveRecord::Migration[7.0]
def change
end
end
If the migration is named in pattern: CreateXXX
then the migration will create a new table with the name XXX
. You can add column names and types to be created as well:
rake db:new_migration name=CreatePages options=title:string/content:text
Which should produce:
class CreatePages < ActiveRecord::Migration[7.0]
def change
create_table :pages do |t|
t.string :title
t.text :content
end
end
end
To add or remove columns to tables that already exist You can name your migrations and provide list of columns to do that. Anything named "AddColumnToTable" with some column options, will create a migration adding those columns to that table. Here's an Example:
rake db:new_migration name=AddCheeseToPages options=cheese:string
Which will produce:
class AddCheeseToPages < ActiveRecord::Migration[7.0]
def change
add_column :pages, :cheese, :string
end
end
If you'd like to remove columns, name it "RemoveColumnFromTable", Here's an example:
rake db:new_migration name=RemoveCheeseFromPages options=cheese:string
Which will produce:
class RemoveCheeseFromPages < ActiveRecord::Migration[7.0]
def change
remove_column :pages, :cheese, :string
end
end
You can also add an index to a new column:
rake db:new_migration name=AddUsernameToPages options=username:string:index
Which will produce:
class AddUsernameToPages < ActiveRecord::Migration[7.0]
def change
add_column :pages, :username, :string
add_index :pages, :username
end
end
You can add multiple columns to the migration
- Write a Readme.
- Support database_url, and using environment variables as the database thing.
- Add an example Camping App using the Extension.
- Finish work on Camping 3.0 so that this gem can be used like legit.
- Write some guides on how to use Active Record.
- Add copyright thing.
- Add Feedback to Guidebook Install Command.
- Test and document generators for migration
- Test and document migrations.
- Add camping as a development dependency.
- Add a Gemfile.
- Get default database locations and config.kdl stuff working too.
- Enter the thing into Git.
- Have a default spot that settings are grabbed from. (/db/config.kdl)
- Have a setting where a database connection string is grabbed by default
- Test that settings added using #set on the Camping app take precedence.
- Generate config.yml for the rake tasks stuff thing. It expects it.
- Write tests with Rake.
- Also test using Rake.
- Write a generator that adds a db/ folder and a db/ config.kdl
- Test the gem with a greenfield project.
- Move the db directory to test, then rewrite the test suite to generate these files.
- Map migration commands to Rake automatically somehow.
- Map Generators to rake somehow too.
- Add config.yml generation to the install sequence.
- Improve Guidebook to NOT add anything to the rake file if cairn is included and the standalone_migrations tasks.