Class: ActiveRecord::Tasks::SQLiteDatabaseTasks
- Inherits:
-
Object
- Object
- ActiveRecord::Tasks::SQLiteDatabaseTasks
- Defined in:
- lib/active_record/tasks/sqlite_database_tasks.rb
Overview
:nodoc:
Instance Method Summary collapse
- #charset ⇒ Object
- #create ⇒ Object
- #drop ⇒ Object
-
#initialize(configuration, root = ActiveRecord::Tasks::DatabaseTasks.root) ⇒ SQLiteDatabaseTasks
constructor
A new instance of SQLiteDatabaseTasks.
- #purge ⇒ Object
- #structure_dump(filename) ⇒ Object
- #structure_load(filename) ⇒ Object
Constructor Details
#initialize(configuration, root = ActiveRecord::Tasks::DatabaseTasks.root) ⇒ SQLiteDatabaseTasks
Returns a new instance of SQLiteDatabaseTasks.
6 7 8 |
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 6 def initialize(configuration, root = ActiveRecord::Tasks::DatabaseTasks.root) @configuration, @root = configuration, root end |
Instance Method Details
#charset ⇒ Object
30 31 32 |
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 30 def charset connection.encoding end |
#create ⇒ Object
10 11 12 13 14 15 |
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 10 def create raise DatabaseAlreadyExists if File.exist?(configuration['database']) establish_connection configuration connection end |
#drop ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 17 def drop require 'pathname' path = Pathname.new configuration['database'] file = path.absolute? ? path.to_s : File.join(root, path) FileUtils.rm(file) if File.exist?(file) end |
#purge ⇒ Object
25 26 27 28 |
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 25 def purge drop create end |
#structure_dump(filename) ⇒ Object
34 35 36 37 |
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 34 def structure_dump(filename) dbfile = configuration['database'] `sqlite3 #{dbfile} .schema > #{filename}` end |
#structure_load(filename) ⇒ Object
39 40 41 42 |
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 39 def structure_load(filename) dbfile = configuration['database'] `sqlite3 #{dbfile} < "#{filename}"` end |