Sha256: ca797cb4611d4683d9e64481adb53ccee6639137fb5de9dc7038ef191e324f6e

Contents?: true

Size: 1.45 KB

Versions: 20

Compression:

Stored size: 1.45 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)
      rescue Errno::ENOENT => error
        raise NoDatabaseError.new(error.message)
      end

      def purge
        drop
      rescue NoDatabaseError
      ensure
        create
      end

      def charset
        connection.encoding
      end

      def structure_dump(filename, extra_flags)
        dbfile = configuration["database"]
        flags = extra_flags.join(" ") if extra_flags
        `sqlite3 #{flags} #{dbfile} .schema > #{filename}`
      end

      def structure_load(filename, extra_flags)
        dbfile = configuration["database"]
        flags = extra_flags.join(" ") if extra_flags
        `sqlite3 #{flags} #{dbfile} < "#{filename}"`
      end

      private

        def configuration
          @configuration
        end

        def root
          @root
        end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
activerecord-5.1.7 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.7.rc1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.6.2 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.6.1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.6 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.5 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.5.rc1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.4 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.4.rc1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.3 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.3.rc3 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.3.rc2 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.3.rc1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.2 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.2.rc1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.0 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.0.rc2 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.0.rc1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.1.0.beta1 lib/active_record/tasks/sqlite_database_tasks.rb