Class: ActiveRecord::Tasks::SQLiteDatabaseTasks

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

Overview

:nodoc:

Instance Method Summary collapse

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

#charsetObject



34
35
36
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 34

def charset
  connection.encoding
end

#createObject



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

#dropObject



17
18
19
20
21
22
23
24
25
# 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)
rescue Errno::ENOENT => error
  raise NoDatabaseError.new(error.message)
end

#purgeObject



27
28
29
30
31
32
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 27

def purge
  drop
rescue NoDatabaseError
ensure
  create
end

#structure_dump(filename, extra_flags) ⇒ Object



38
39
40
41
42
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 38

def structure_dump(filename, extra_flags)
  dbfile = configuration["database"]
  flags = extra_flags.join(" ") if extra_flags
  `sqlite3 #{flags} #{dbfile} .schema > #{filename}`
end

#structure_load(filename, extra_flags) ⇒ Object



44
45
46
47
48
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 44

def structure_load(filename, extra_flags)
  dbfile = configuration["database"]
  flags = extra_flags.join(" ") if extra_flags
  `sqlite3 #{flags} #{dbfile} < "#{filename}"`
end