blob: de8b16627e41062fd7d6dcc545d5acc1635d7b80 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
module ActiveRecord
module Tasks # :nodoc:
class SQLiteDatabaseTasks # :nodoc:
delegate :connection, :establish_connection, to: ActiveRecord::Base
def initialize(configuration, root = Rails.root)
@configuration, @root = configuration, root
end
def create
raise DatabaseAlreadyExists if File.exist?(configuration['database'])
establish_connection configuration
connection
end
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
alias :purge :drop
def charset
connection.encoding
end
def structure_dump(filename)
dbfile = configuration['database']
`sqlite3 #{dbfile} .schema > #{filename}`
end
def structure_load(filename)
dbfile = configuration['database']
`sqlite3 #{dbfile} < "#{filename}"`
end
private
def configuration
@configuration
end
def root
@root
end
end
end
end
|