Sha256: eadbde4856c158bbe01da8394de3556772c7ca08ab9e96d9b774166a88f3eb44

Contents?: true

Size: 1.27 KB

Versions: 18

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
        bytea :key, null: false
        String :fingerprint, unique: true, 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

18 entries across 18 versions & 1 rubygems

Version Path
slosilo-3.0.2.pre.224 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-3.0.2.pre.5 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-3.0.2.pre.44 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-3.0.2.pre.42 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-3.0.2.pre.2 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-3.0.2.pre.35 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-0.0.0 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-3.0.1 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-3.0.0 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-2.2.2 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-2.2.1 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-2.1.1 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-2.0.1 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-2.0.0 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-1.1.0 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-1.0.0 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-0.4.1 lib/slosilo/adapters/sequel_adapter/migration.rb
slosilo-0.4.0 lib/slosilo/adapters/sequel_adapter/migration.rb