Class: ApplicationSeeds::Database
- Inherits:
-
Object
- Object
- ApplicationSeeds::Database
- Defined in:
- lib/application_seeds/database.rb
Class Method Summary collapse
Class Method Details
.connection ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/application_seeds/database.rb', line 5 def connection return @connection unless @connection.nil? database_config = YAML.load(ERB.new(File.read("config/database.yml")).result)[Rails.env] pg_config = {} pg_config[:dbname] = database_config['database'] pg_config[:host] = database_config['host'] if database_config['host'] pg_config[:port] = database_config['port'] if database_config['port'] pg_config[:user] = database_config['username'] if database_config['username'] pg_config[:password] = database_config['password'] if database_config['password'] @connection = PG.connect(pg_config) end |
.create_metadata_table ⇒ Object
20 21 22 23 |
# File 'lib/application_seeds/database.rb', line 20 def connection.exec('DROP TABLE IF EXISTS application_seeds;') connection.exec('CREATE TABLE application_seeds (dataset varchar(255));') end |
.without_foreign_keys ⇒ Object
25 26 27 28 29 30 31 32 |
# File 'lib/application_seeds/database.rb', line 25 def without_foreign_keys drop_foreign_keys_sql = generate_drop_foreign_keys_sql create_foreign_keys_sql = generate_create_foreign_keys_sql connection.exec(drop_foreign_keys_sql) yield connection.exec(create_foreign_keys_sql) end |