Class: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Inherits:
-
Object
- Object
- ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
- Defined in:
- lib/versioned_record/connection_adapters/postgresql.rb
Instance Method Summary collapse
-
#create_table(table_name, options = {}) ⇒ Object
Provide versioned: true to create a versioned table Note that schema.rb cannot be used with versioned tables.
Instance Method Details
#create_table(table_name, options = {}) ⇒ Object
Provide versioned: true to create a versioned table Note that schema.rb cannot be used with versioned tables
7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/versioned_record/connection_adapters/postgresql.rb', line 7 def create_table(table_name, = {}) if [:versioned] super(table_name, .merge(id: false)) do |table| table.column :id, :serial table.integer :version, default: 0 table.boolean :is_current_version, default: true yield(table) end add_index(table_name, [:id, :version], unique: true, name: "#{table_name}_versioned_pkey") execute("ALTER TABLE #{table_name} ADD PRIMARY KEY USING INDEX #{table_name}_versioned_pkey") else super end end |