Sha256: a7f4fa49772eb64f582bf52dc941e20df31e3ea77e0182f4e86d17c352c67810

Contents?: true

Size: 1.15 KB

Versions: 43

Compression:

Stored size: 1.15 KB

Contents

module ActiveRecord
  module Tasks # :nodoc:
    class SQLiteDatabaseTasks # :nodoc:
      delegate :connection, :establish_connection, to: ActiveRecord::Base

      def initialize(configuration, root = ActiveRecord::Tasks::DatabaseTasks.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

Version data entries

43 entries across 43 versions & 1 rubygems

Version Path
activerecord-4.0.13 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.0.13.rc1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.1.7.1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.0.11.1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.0.12 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.1.7 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.0.11 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.0.10 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.1.6 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.1.6.rc2 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.0.10.rc2 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.1.6.rc1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.0.10.rc1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.0.9 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.1.5 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.1.4 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.0.8 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.1.3 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.0.7 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-4.0.6 lib/active_record/tasks/sqlite_database_tasks.rb