Module: Whatup::Server::DbInit
Class Method Summary collapse
-
.setup_db! ⇒ Object
Sets up our database, deleting all existing data.
Methods included from Redirection
Class Method Details
.setup_db! ⇒ Object
Sets up our database, deleting all existing data.
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/whatup/server/db_init.rb', line 13 def setup_db! db = "#{Dir.home}/.whatup.db" SQLite3::Database.new(db) unless File.exist?(db) ActiveRecord::Base.establish_connection adapter: 'sqlite3', database: db ActiveRecord::Base.connection.execute " DROP TABLE IF EXISTS clients_rooms;\n DROP TABLE IF EXISTS clients;\n DROP TABLE IF EXISTS messages;\n DROP TABLE IF EXISTS rooms;\n SQL\n\n if Whatup.testing?\n # We silence output here, so that tests don't get cluttered\n redirect(stdout: StringIO.new) { create_tables! }\n return\n end\n\n create_tables!\nend\n" |