Class: ActiveRecord::Tasks::SQLiteDatabaseTasks

Inherits:
Object
  • Object
show all
Defined in:
activerecord/lib/active_record/tasks/sqlite_database_tasks.rb

Overview

:nodoc:

Instance Method Summary collapse

Constructor Details

#initialize(configuration, root = Rails.root) ⇒ SQLiteDatabaseTasks

Returns a new instance of SQLiteDatabaseTasks.



6
7
8
# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 6

def initialize(configuration, root = Rails.root)
  @configuration, @root = configuration, root
end

Instance Method Details

#charsetObject



26
27
28
# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 26

def charset
  connection.encoding
end

#createObject



10
11
12
13
14
15
# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 10

def create
  raise DatabaseAlreadyExists if File.exist?(configuration['database'])

  establish_connection configuration
  connection
end

#dropObject Also known as: purge



17
18
19
20
21
22
23
# File 'activerecord/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

#structure_dump(filename) ⇒ Object



30
31
32
33
# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 30

def structure_dump(filename)
  dbfile = configuration['database']
  `sqlite3 #{dbfile} .schema > #{filename}`
end

#structure_load(filename) ⇒ Object



35
36
37
38
# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 35

def structure_load(filename)
  dbfile = configuration['database']
  `sqlite3 #{dbfile} < "#{filename}"`
end