Sha256: 67e9c3f3cfe29a01055769279a45baa8f4e05882343946d42ee7815c30afad65

Contents?: true

Size: 1.56 KB

Versions: 2

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

ActiveRecord::Schema.define do
  execute('CREATE extension IF NOT EXISTS "hstore";')
  execute('CREATE extension IF NOT EXISTS "pgcrypto";')
  execute('CREATE extension IF NOT EXISTS "uuid-ossp";')

  # create ENUM if it does not exist yet
  begin
    execute('CREATE TYPE vendor_type AS ENUM (\'wholesaler\', \'retailer\');')
  rescue ActiveRecord::StatementInvalid
    execute('ALTER TYPE vendor_type ADD VALUE IF NOT EXISTS \'wholesaler\';')
    execute('ALTER TYPE vendor_type ADD VALUE IF NOT EXISTS \'retailer\';')
  end

  create_table :vendors, id: :uuid, force: :cascade do |t|
    t.string :name, null: true
    t.text :hours
    t.text :preferences

    if t.respond_to?(:json)
      t.json :pure_json_data
      t.json :data
    else
      t.text :data
    end

    if t.respond_to?(:hstore)
      t.hstore :config
    else
      t.text :config
    end

    if t.respond_to?(:jsonb)
      t.jsonb :pure_jsonb_data
      t.jsonb :settings
      t.jsonb :json_data, null: false, default: {}
    else
      t.text :settings
      t.text :json_data
    end

    t.column :vendor_type, :vendor_type

    t.datetime :created_at
    t.datetime :updated_at
  end

  create_table :alarms, force: true do |t|
    t.column :device_id, :integer, null: false
    t.column :alarm_type, :integer, null: false
    t.column :status, :integer, null: false
    t.column :metadata, :text
    t.column :secret_key, :binary
    t.datetime :created_at
    t.datetime :updated_at
  end

  add_index :alarms, [:device_id, :alarm_type], unique: true, where: 'status <> 0'
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
activerecord-import-1.6.0 test/schema/postgresql_schema.rb
activerecord-import-1.5.1 test/schema/postgresql_schema.rb