Sha256: 0bbd027cd2d540f798983865ef770a1b97122e66484aa91131e8062a6cbc9422

Contents?: true

Size: 1.07 KB

Versions: 1

Compression:

Stored size: 1.07 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
      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

1 entries across 1 versions & 1 rubygems

Version Path
slosilo-0.1.2 lib/slosilo/adapters/sequel_adapter/migration.rb