Class: ActiveRecord::Tasks::SQLiteDatabaseTasks
- Inherits:
-
Object
- Object
- ActiveRecord::Tasks::SQLiteDatabaseTasks
- Defined in:
- lib/active_record/tasks/sqlite_database_tasks.rb
Overview
:nodoc:
Class Method Summary collapse
Instance Method Summary collapse
- #charset ⇒ Object
- #create ⇒ Object
- #drop ⇒ Object
-
#initialize(db_config, root = ActiveRecord::Tasks::DatabaseTasks.root) ⇒ SQLiteDatabaseTasks
constructor
A new instance of SQLiteDatabaseTasks.
- #purge ⇒ Object
- #structure_dump(filename, extra_flags) ⇒ Object
- #structure_load(filename, extra_flags) ⇒ Object
Constructor Details
#initialize(db_config, root = ActiveRecord::Tasks::DatabaseTasks.root) ⇒ SQLiteDatabaseTasks
Returns a new instance of SQLiteDatabaseTasks.
10 11 12 13 |
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 10 def initialize(db_config, root = ActiveRecord::Tasks::DatabaseTasks.root) @db_config = db_config @root = root end |
Class Method Details
.using_database_configurations? ⇒ Boolean
6 7 8 |
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 6 def self.using_database_configurations? true end |
Instance Method Details
#charset ⇒ Object
40 41 42 |
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 40 def charset connection.encoding end |
#create ⇒ Object
15 16 17 18 19 20 |
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 15 def create raise DatabaseAlreadyExists if File.exist?(db_config.database) establish_connection connection end |
#drop ⇒ Object
22 23 24 25 26 27 28 29 |
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 22 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.) end |
#purge ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 31 def purge connection.disconnect! drop rescue NoDatabaseError ensure create connection.reconnect! end |
#structure_dump(filename, extra_flags) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 44 def structure_dump(filename, extra_flags) args = [] args.concat(Array(extra_flags)) if extra_flags 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" end run_cmd("sqlite3", args, filename) end |
#structure_load(filename, extra_flags) ⇒ Object
60 61 62 63 |
# File 'lib/active_record/tasks/sqlite_database_tasks.rb', line 60 def structure_load(filename, extra_flags) flags = extra_flags.join(" ") if extra_flags `sqlite3 #{flags} #{db_config.database} < "#{filename}"` end |