Sha256: 9d47f3b7451c4d687111fdbbdd0a25a252659272137f2207e0acbb5e03da0290

Contents?: true

Size: 1.27 KB

Versions: 3

Compression:

Stored size: 1.27 KB

Contents

require 'sequel'

module Slosilo
  module Adapters::SequelAdapter::Migration
    # The default name of the table to hold the keys
    DEFAULT_KEYSTORE_TABLE = :slosilo_keystore

    # Sets up default keystore table name
    def self.extended(db)
      db.keystore_table ||= DEFAULT_KEYSTORE_TABLE
    end
    
    # Keystore table name. If changing this do it immediately after loading the extension.
    attr_accessor :keystore_table

    # Create the table for holding keys
    def create_keystore_table
      # docs say to not use create_table? in migration;
      # but we really want this to be robust in case there are any previous installs
      # and we can't use table_exists? because it rolls back
      create_table? keystore_table do
        String :id, primary_key: true
        # Note: currently only postgres is supported
        bytea :key, null: false
      end
    end
    
    # Drop the table
    def drop_keystore_table
      drop_table keystore_table
    end
  end
  
  module Extension
    def slosilo_keystore
      extend Slosilo::Adapters::SequelAdapter::Migration
    end
  end
  
  Sequel::Database.send :include, Extension
end

Sequel.migration do
  up do
    slosilo_keystore
    create_keystore_table
  end
  down do
    slosilo_keystore
    drop_keystore_table
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
slosilo-0.2.4 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-0.2.3 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-0.2.2 lib/slosilo/adapters/sequel_adapter/migration.rb