Class: ActiveRecord::Tasks::SQLiteDatabaseTasks
Overview
Instance Method Summary
collapse
#charset, #collation, using_database_configurations?
Constructor Details
#initialize(db_config, root = ActiveRecord::Tasks::DatabaseTasks.root) ⇒ SQLiteDatabaseTasks
Returns a new instance of SQLiteDatabaseTasks.
6
7
8
9
|
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 6
def initialize(db_config, root = ActiveRecord::Tasks::DatabaseTasks.root)
@db_config = db_config
@root = root
end
|
Instance Method Details
#check_current_protected_environment!(db_config, migration_class) ⇒ Object
58
59
60
61
62
63
64
65
66
|
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 58
def check_current_protected_environment!(db_config, migration_class)
super
rescue ActiveRecord::StatementInvalid => e
case e.cause
when SQLite3::ReadOnlyException
else
raise e
end
end
|
#create ⇒ Object
11
12
13
14
15
16
|
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 11
def create
raise DatabaseAlreadyExists if File.exist?(db_config.database)
establish_connection
connection
end
|
#drop ⇒ Object
18
19
20
21
22
23
24
25
|
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 18
def drop
db_path = db_config.database
file = File.absolute_path?(db_path) ? db_path : File.join(root, db_path)
FileUtils.rm(file)
FileUtils.rm_f(["#{file}-shm", "#{file}-wal"])
rescue Errno::ENOENT => error
raise NoDatabaseError.new(error.message)
end
|
#purge ⇒ Object
27
28
29
30
31
32
33
34
|
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 27
def purge
connection.disconnect!
drop
rescue NoDatabaseError
ensure
create
connection.reconnect!
end
|
#structure_dump(filename, extra_flags) ⇒ Object
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 36
def structure_dump(filename, )
args = []
args.concat(Array()) if
args << db_config.database
ignore_tables = ActiveRecord::SchemaDumper.ignore_tables
if ignore_tables.any?
ignore_tables = connection.data_sources.select { |table| ignore_tables.any? { |pattern| pattern === table } }
condition = ignore_tables.map { |table| connection.quote(table) }.join(", ")
args << "SELECT sql || ';' FROM sqlite_master WHERE tbl_name NOT IN (#{condition}) ORDER BY tbl_name, type DESC, name"
else
args << ".schema --nosys"
end
run_cmd("sqlite3", *args, out: filename)
end
|
#structure_load(filename, extra_flags) ⇒ Object
53
54
55
56
|
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 53
def structure_load(filename, )
flags = .join(" ") if
`sqlite3 #{flags} #{db_config.database} < "#{filename}"`
end
|