Class: ActiveRecord::Tasks::SQLiteDatabaseTasks
- Defined in:
- activerecord/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.
12 13 14 15 |
# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 12 def initialize(db_config, root = ActiveRecord::Tasks::DatabaseTasks.root) @db_config = db_config @root = root end |
Class Method Details
.using_database_configurations? ⇒ Boolean
8 9 10 |
# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 8 def self.using_database_configurations? true end |
Instance Method Details
#charset ⇒ Object
41 42 43 |
# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 41 def charset connection.encoding end |
#create ⇒ Object
17 18 19 20 21 22 |
# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 17 def create raise DatabaseAlreadyExists if File.exist?(db_config.database) establish_connection(db_config) connection end |
#drop ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 24 def drop require "pathname" path = Pathname.new(db_config.database) file = path.absolute? ? path.to_s : File.join(root, path) FileUtils.rm(file) rescue Errno::ENOENT => error raise NoDatabaseError.new(error.) end |
#purge ⇒ Object
34 35 36 37 38 39 |
# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 34 def purge drop rescue NoDatabaseError ensure create end |
#structure_dump(filename, extra_flags) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 45 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? 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 'activerecord/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 |