Class: TotemActiverecord::ShellCmds::Db

Inherits:
Totem::ShellCmds::Base
  • Object
show all
Defined in:
lib/totem_activerecord/shell_cmds/db.rb

Instance Method Summary collapse

Instance Method Details

#createObject



13
14
15
16
17
18
19
# File 'lib/totem_activerecord/shell_cmds/db.rb', line 13

def create
  ActiveRecord::Base.establish_connection(TotemActiverecord.config.merge('database' => nil))
  ActiveRecord::Base.connection.create_database(TotemActiverecord.config['database'])
  ActiveRecord::Base.establish_connection(TotemActiverecord.config)

  return true
end

#dropObject



21
22
23
24
25
# File 'lib/totem_activerecord/shell_cmds/db.rb', line 21

def drop
  ActiveRecord::Base.connection.drop_database(TotemActiverecord.config['database'])

  return true
end

#migrateObject



27
28
29
30
31
32
33
34
# File 'lib/totem_activerecord/shell_cmds/db.rb', line 27

def migrate
  ActiveRecord::Migration.verbose = true
  ActiveRecord::Migrator.migrate(TotemActiverecord.migrations_path)

  TotemActiverecord.reconnect

  return true
end

#rollbackObject



36
37
38
39
40
41
# File 'lib/totem_activerecord/shell_cmds/db.rb', line 36

def rollback
  ActiveRecord::Migrator.rollback(TotemActiverecord.migrations_path, 1)
  TotemActiverecord.reconnect

  return true
end

#runObject



4
5
6
7
8
9
10
11
# File 'lib/totem_activerecord/shell_cmds/db.rb', line 4

def run
  case @args[0]
  when 'create'   then create
  when 'drop'     then drop
  when 'migrate'  then migrate
  when 'rollback' then rollback
  end
end