Class: ActiveRecord::Tasks::SQLiteDatabaseTasks
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | activerecord/lib/active_record/tasks/sqlite_database_tasks.rb |
Class Attribute Summary
Class Method Summary
Instance Attribute Summary
- #db_config readonly private
- #root readonly private
Instance Method Summary
Constructor Details
.new(db_config, root = ActiveRecord::Tasks::DatabaseTasks.root) ⇒ SQLiteDatabaseTasks
# File 'activerecord/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 Attribute Details
.using_database_configurations? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 6
def self.using_database_configurations? true end
Instance Attribute Details
#db_config (readonly, private)
[ GitHub ]# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 66
attr_reader :db_config, :root
#root (readonly, private)
[ GitHub ]Instance Method Details
#charset
[ GitHub ]# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 40
def charset connection.encoding end
#connection (private)
[ GitHub ]# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 68
def connection ActiveRecord::Base.lease_connection end
#create
# File 'activerecord/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
[ GitHub ]# File 'activerecord/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
#establish_connection(config = db_config) (private)
[ GitHub ]# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 72
def establish_connection(config = db_config) ActiveRecord::Base.establish_connection(config) connection.connect! end
#purge
[ GitHub ]# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 31
def purge connection.disconnect! drop rescue NoDatabaseError ensure create connection.reconnect! end
#run_cmd(cmd, args, out) (private)
[ GitHub ]# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 77
def run_cmd(cmd, args, out) fail run_cmd_error(cmd, args) unless Kernel.system(cmd, *args, out: out) end
#run_cmd_error(cmd, args) (private)
[ GitHub ]# File 'activerecord/lib/active_record/tasks/sqlite_database_tasks.rb', line 81
def run_cmd_error(cmd, args) msg = +"failed to execute:\n" msg << "#{cmd} #{args.join(' ')}\n\n" msg << "Please check the output above for any errors and make sure that `#{cmd}` is installed in your PATH and has proper permissions.\n\n" msg end
#structure_dump(filename, extra_flags)
[ GitHub ]# File 'activerecord/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 --nosys" end run_cmd("sqlite3", args, filename) end
#structure_load(filename, extra_flags)
[ GitHub ]# 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