Topic: Create Databases Needed by Kete

Topic Type: Topic

The steps necessary for creating databases supporting an installation of Kete.

Originally written by Walter McGinnis, Kete Project Lead for Katipo Communications, Ltd.

Part of the Installation Guide

MySQL instructions

Important Note: This step assumes that you are logged in as the user who will be running your Kete. For demos and development this is likely your normal account, for production this is the "kete" account if you have followed the conventions laid forth in the last step. You'll also need your MySQL root user's password to do this step.

Set up databases

We need to set up our databases for use with our new application. This is pretty simple, but does require some simple editing of a file and running some MySQL stuff. Here goes:

$ cd ~/apps/your_app/
$ cp config/database.example config/database.yml

Open config/database.yml in your text editor. Edit username and password settings to suit. You'll also want to change occurances of "kete_" to "your_app_", for example "kete_development" becomes "your_app_development".

After saving config/database.yml, you want to open a mysql session and create your databases and grant rights on them to whatever you chose for username in the file:

$ mysql -u root -p mysql # enter the mysql root password
...
mysql> create database your_app_production;
mysql> grant all on your_app_production.* to 'the_username_you_chose'@'localhost' identified by 'the_password_you_chose';
mysql> create database your_app_development;
mysql> grant all on your_app_development.* to 'the_username_you_chose'@'localhost';
mysql> create database your_app_test;
mysql> grant all on your_app_test.* to 'the_username_you_chose'@'localhost';
mysql> quit;

PostgreSQL instructions

Create Postgres user

This will need to be done as your database super-user, or a user empowered to create roles.

$ createuser kete
Should this user be a super-user? - NO
Should this user be allowed to create databases? - YES
Should this user be allowed to create more users? - NO

Refer to the PostgreSQL manual for further information if you need to configure a password or remote access; otherwise, if you are using a local database and unix authentication, no further setup is necessary.

The database will actually be created later by the deployment stage. 

Configure database

Follow the instructions above for MySQL to get a new config/database.yml, and edit accordingly. Set the "adapter" to "postgresql" for each environment.



Next step:
Configure Backgroundrb

Discuss This Topic

There are 5 comments in this discussion.

Read and join this discussion

samv said bootstrap tries to apply MySQL queries

It seems that Kete is not picking up my database configuration at a late stage in the process; any ideas?
Excerpt from config/database.yml:

 development:
   adapter: postgresql
   database: kete_dev
   username: kete
   password:

I can connect to this database and bootstrap; however it fails at the "CreateConfigurableSettings" stage;

  kete@kete:~/kete$ rake db:bootstrap RAILS_ENV=development
(in /home/kete/kete)
dropdb: database removal failed: ERROR:  database "kete_dev" is being accessed by other users
"kete_dev already exists"
== 1 CreateTopicTypes: migrating ==============================================
-- create_table(:topic_types)
NOTICE:  CREATE TABLE will create implicit sequence "topic_types_id_seq" for serial column "topic_types.id"
  ...
 == 42 AddTechAdminRole: migrating =============================================
== 42 AddTechAdminRole: migrated (0.0236s) ====================================

== 43 CreateConfigurableSettings: migrating ===================================
rake aborted!
PGError: ERROR:  syntax error at or near "ENGINE" at character 369
: CREATE TABLE configurable_settings ("id" serial primary key, "configurable_id" integer DEFAULT NULL, "configurable_type" character varying(255) DEFAULT NULL, "targetable_id" integer DEFAULT NULL, "targetable_type" character varying(255) DEFAULT NULL, "name" character varying(255) NOT NULL, "value_type" character varying(255) DEFAULT NULL, "value" text DEFAULT NULL) ENGINE=InnoDB

(See full trace by running task with --trace)

 Here is the trace:

kete@kete:~/kete$ rake db:migrate --trace RAILS_ENV=development
(in /home/kete/kete)
** Invoke db:migrate (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute db:migrate
== 43 CreateConfigurableSettings: migrating ===================================
rake aborted!
PGError: ERROR:  syntax error at or near "ENGINE" at character 369
: CREATE TABLE configurable_settings ("id" serial primary key, "configurable_id" integer DEFAULT NULL, "configurable_type" character varying(255) DEFAULT NULL, "targetable_id" integer DEFAULT NULL, "targetable_type" character varying(255) DEFAULT NULL, "name" character varying(255) NOT NULL, "value_type" character varying(255) DEFAULT NULL, "value" text DEFAULT NULL) ENGINE=InnoDB
/home/kete/kete/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract_adapter.rb:150:in `log'
 /home/kete/kete/vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb:407:in `execute'
/home/kete/kete/vendor/rails/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb:104:in `create_table_without_redhillonrails_core'
/home/kete/kete/vendor/plugins/redhillonrails_core/lib/red_hill_consulting/core/active_record/connection_adapters/schema_statements.rb:10:in `create_table'
/home/kete/kete/vendor/plugins/acts_as_configurable/lib/configurable_setting.rb:10:in `create_table'
./db/migrate//043_create_configurable_settings.rb:3:in `up_without_benchmarks'
/home/kete/kete/vendor/rails/activerecord/lib/active_record/migration.rb:219:in `send'
/home/kete/kete/vendor/rails/activerecord/lib/active_record/migration.rb:219:in `migrate'
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure'
/home/kete/kete/vendor/rails/activerecord/lib/active_record/migration.rb:219:in `migrate'
/home/kete/kete/vendor/rails/activerecord/lib/active_record/migration.rb:348:in `migrate'
/home/kete/kete/vendor/rails/activerecord/lib/active_record/migration.rb:339:in `each'
/home/kete/kete/vendor/rails/activerecord/lib/active_record/migration.rb:339:in `migrate'
/home/kete/kete/vendor/rails/activerecord/lib/active_record/migration.rb:307:in `up'
/home/kete/kete/vendor/rails/activerecord/lib/active_record/migration.rb:298:in `migrate'
 /home/kete/kete/vendor/rails/railties/lib/tasks/databases.rake:85
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `call'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:546:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:541:in `execute'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:508:in `invoke_with_call_chain'
/usr/lib/ruby/1.8/thread.rb:135:in `synchronize'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:501:in `invoke_with_call_chain'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:494:in `invoke'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1931:in `invoke_task'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `each'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1909:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1903:in `top_level'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1881:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1948:in `standard_exception_handling'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/lib/rake.rb:1878:in `run'
/usr/lib/ruby/gems/1.8/gems/rake-0.8.1/bin/rake:31
/usr/bin/rake:19:in `load'
/usr/bin/rake:19  
kete@kete:~/kete$
Walter McGinnis said Re: bootstrap tries to apply MySQL queries

Hi Sam,

The db:bootstrap task is actually drops the db, creates a new blank version of it, then loads in the schema via a db:migrate, then loads default data.

So, it's not MySQL queries per se. It's actually that PG thinks that someone is connected to the database and therefore refuses to drop it.

In lib/tasks/bootstrap.rake try replacing this:

 task :bootstrap => ['db:drop', 'db:create', 'db:bootstrap:load']

with this:

 task :bootstrap => ['db:rewind', 'db:bootstrap:load']

and see if that works. Please report back here.

Cheers,
Walter

Walter McGinnis said Sorry, spoke too soon.

Ah, that "Engine=InnoDb" code is in a plugin which is why I wasn't familiar with it. I'll look into it tomorrow and let you know when there is a fix.

Thank you for your contribution of the PostgreSQL segment, by the way.

Cheers,
Walter

Walter McGinnis said Re: bootstrap tries to apply MySQL queries

Alright, tracked it down to the acts_as_configurable plugin.  I'll see if we can get them this to be db agnostic, but in the meantime you can try this: 

 In vendor/plugins/acts_as_configurable/lib/configurable_setting.rb, replace line 10 with this:

 self.connection.create_table :configurable_settings do |t|

Let me know how that goes.

Cheers,

Walter 

Tags: Postgresql, bootstrap

Walter McGinnis said Re: bootstrap tries to apply MySQL queries

Here's a more permanent patch.  Works with MySQL, if you could test it with PG, I would appreciate it.  If it works with PG, I'll commit it to trunk:

    table_options = String.new
    table_options = 'ENGINE=InnoDB' if 'MySQL' == ActiveRecord::Base.connection.adapter_name
    self.connection.create_table :configurable_settings, :options => table_options do |t|

This is still in  vendor/plugins/acts_as_configurable/lib/configuration_setting.rb, replace line 10.

I'm having a hard time tracking down the maintainer of the acts_as_configurable, so if this works, we'll commit locally as a modification of the plugin as it comes with Kete.

Cheers,

Walter 


Tags: Postgresql, bootstrap, acts_as_configurable

join this discussion

Creative Commons Attribution-Share Alike 3.0 New Zealand License
Create Databases Needed by Kete by Walter McGinnis is licensed under a Creative Commons Attribution-Share Alike 3.0 New Zealand License