Sha256: d5e279e72841d89d70adb536280dcd373110c47cfc4ffbfdff99a703b5ff88f3

Contents?: true

Size: 1.29 KB

Versions: 35

Compression:

Stored size: 1.29 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, error)
      end

      def purge
        drop
      rescue NoDatabaseError
      ensure
        create
      end

      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

35 entries across 35 versions & 4 rubygems

Version Path
activerecord-5.0.7.2 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.0.7.1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.0.7 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.0.6 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.0.6.rc1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.0.5 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.0.5.rc2 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.0.5.rc1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.0.4 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.0.4.rc1 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.0.3 lib/active_record/tasks/sqlite_database_tasks.rb
enju_leaf-1.2.1 vendor/bundle/ruby/2.3/gems/activerecord-5.0.2/lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.0.2 lib/active_record/tasks/sqlite_database_tasks.rb
activerecord-5.0.2.rc1 lib/active_record/tasks/sqlite_database_tasks.rb
autocompl-0.2.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/tasks/sqlite_database_tasks.rb
autocompl-0.2.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/tasks/sqlite_database_tasks.rb
autocompl-0.2.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/tasks/sqlite_database_tasks.rb
autocompl-0.1.2 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/tasks/sqlite_database_tasks.rb
autocompl-0.1.1 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/tasks/sqlite_database_tasks.rb
autocompl-0.1.0 test/dummy/vendor/bundle/ruby/2.3.0/gems/activerecord-5.0.1/lib/active_record/tasks/sqlite_database_tasks.rb