Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #9881: lock_version.patch

File lock_version.patch, 12.5 kB (added by lawrence, 1 year ago)
  • activerecord/lib/active_record/connection_adapters/abstract/schema_definitions.rb

    old new  
    375375      # What can be written like this with the regular calls to column: 
    376376      # 
    377377      #   create_table "products", :force => true do |t| 
    378       #     t.column "shop_id",    :integer 
    379       #     t.column "creator_id", :integer 
    380       #     t.column "name",       :string,   :default => "Untitled" 
    381       #     t.column "value",      :string,   :default => "Untitled" 
    382       #     t.column "created_at", :datetime 
    383       #     t.column "updated_at", :datetime 
     378      #     t.column "shop_id",      :integer 
     379      #     t.column "creator_id",   :integer 
     380      #     t.column "name",         :string,   :default => "Untitled" 
     381      #     t.column "value",        :string,   :default => "Untitled" 
     382      #     t.column "lock_version", :integer,  {:default => 0, :null => false} 
     383      #     t.column "created_at",   :datetime 
     384      #     t.column "updated_at",   :datetime 
    384385      #   end 
    385386      # 
    386387      # Can also be written as follows using the short-hand: 
     
    388389      #   create_table :products do |t| 
    389390      #     t.integer :shop_id, :creator_id 
    390391      #     t.string  :name, :value, :default => "Untitled" 
     392      #     t.lock_version 
    391393      #     t.timestamps 
    392394      #   end 
    393395      # 
    394396      # There's a short-hand method for each of the type values declared at the top. And then there's  
     397      # TableDefinition#lock_version that'll add lock_version as integer not nullable with default 0, and  
    395398      # TableDefinition#timestamps that'll add created_at and updated_at as datetimes. 
    396399      def column(name, type, options = {}) 
    397400        column = self[name] || ColumnDefinition.new(@base, name, type) 
     
    415418        EOV 
    416419      end 
    417420       
     421      # Short-hand method for adding column lock_version as integer not nullable with default 0 
     422      # This column will then be used to manage optimistic locking. 
     423      def lock_version 
     424        column(:lock_version, :integer, {:default => 0, :null => false}) 
     425      end  
     426       
     427      # Short-hand method for adding columns created_at and updated_at as datetimes. 
    418428      def timestamps 
    419429        column(:created_at, :datetime) 
    420430        column(:updated_at, :datetime) 
  • activerecord/test/fixtures/db_definitions/db2.drop.sql

    old new  
    1414DROP TABLE entrants; 
    1515DROP TABLE colnametests; 
    1616DROP TABLE mixins; 
    17 DROP TABLE people; 
    1817DROP TABLE readers; 
    1918DROP TABLE binaries; 
    2019DROP TABLE computers; 
  • activerecord/test/fixtures/db_definitions/db2.sql

    old new  
    129129  PRIMARY KEY (id) 
    130130); 
    131131 
    132 CREATE TABLE people ( 
    133   id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000), 
    134   first_name VARCHAR(40) NOT NULL, 
    135   lock_version INT DEFAULT 0, 
    136   PRIMARY KEY (id) 
    137 ); 
    138  
    139132CREATE TABLE readers ( 
    140133  id INT GENERATED BY DEFAULT AS IDENTITY (START WITH 10000), 
    141134  post_id INT NOT NULL, 
  • activerecord/test/fixtures/db_definitions/firebird.drop.sql

    old new  
    1414DROP TABLE entrants; 
    1515DROP TABLE colnametests; 
    1616DROP TABLE mixins; 
    17 DROP TABLE people; 
    1817DROP TABLE readers; 
    1918DROP TABLE binaries; 
    2019DROP TABLE computers; 
     
    4948DROP GENERATOR entrants_seq; 
    5049DROP GENERATOR colnametests_seq; 
    5150DROP GENERATOR mixins_seq; 
    52 DROP GENERATOR people_seq; 
    5351DROP GENERATOR binaries_seq; 
    5452DROP GENERATOR computers_seq; 
    5553DROP GENERATOR posts_seq; 
  • activerecord/test/fixtures/db_definitions/firebird.sql

    old new  
    160160CREATE GENERATOR mixins_seq; 
    161161SET GENERATOR mixins_seq TO 10000; 
    162162 
    163 CREATE TABLE people ( 
    164   id BIGINT NOT NULL, 
    165   first_name VARCHAR(40), 
    166   lock_version INTEGER DEFAULT 0 NOT NULL, 
    167   PRIMARY KEY (id) 
    168 ); 
    169 CREATE GENERATOR people_seq; 
    170 SET GENERATOR people_seq TO 10000; 
    171  
    172163CREATE TABLE readers ( 
    173164    id BIGINT NOT NULL, 
    174165    post_id BIGINT NOT NULL, 
  • activerecord/test/fixtures/db_definitions/frontbase.drop.sql

    old new  
    1414DROP TABLE entrants CASCADE; 
    1515DROP TABLE colnametests CASCADE; 
    1616DROP TABLE mixins CASCADE; 
    17 DROP TABLE people CASCADE; 
    1817DROP TABLE readers CASCADE; 
    1918DROP TABLE binaries CASCADE; 
    2019DROP TABLE computers CASCADE; 
  • activerecord/test/fixtures/db_definitions/frontbase.sql

    old new  
    145145); 
    146146SET UNIQUE FOR mixins(id); 
    147147 
    148 CREATE TABLE people ( 
    149   id integer DEFAULT unique, 
    150   first_name varchar(65536), 
    151   lock_version integer default 0, 
    152   PRIMARY KEY  (id) 
    153 ); 
    154 SET UNIQUE FOR people(id); 
    155  
    156148CREATE TABLE readers ( 
    157149  id integer DEFAULT unique, 
    158150  post_id INTEGER NOT NULL, 
  • activerecord/test/fixtures/db_definitions/mysql.drop.sql

    old new  
    1414DROP TABLE entrants; 
    1515DROP TABLE colnametests; 
    1616DROP TABLE mixins; 
    17 DROP TABLE people; 
    1817DROP TABLE readers; 
    1918DROP TABLE binaries; 
    2019DROP TABLE computers; 
  • activerecord/test/fixtures/db_definitions/mysql.sql

    old new  
    130130  PRIMARY KEY  (`id`) 
    131131) TYPE=InnoDB; 
    132132 
    133 CREATE TABLE `people` ( 
    134   `id` INTEGER NOT NULL auto_increment PRIMARY KEY, 
    135   `first_name` VARCHAR(40) NOT NULL, 
    136   `lock_version` INTEGER NOT NULL DEFAULT 0 
    137 ) TYPE=InnoDB; 
    138  
    139133CREATE TABLE `readers` ( 
    140134    `id` int(11) NOT NULL auto_increment PRIMARY KEY, 
    141135    `post_id` INTEGER NOT NULL, 
  • activerecord/test/fixtures/db_definitions/openbase.sql

    old new  
    180180CREATE PRIMARY KEY mixins (id)  
    181181go 
    182182 
    183 CREATE TABLE people ( 
    184   id integer NOT NULL UNIQUE INDEX DEFAULT _rowid, 
    185   first_name text, 
    186   lock_version integer default 0 
    187 )  
    188 go 
    189 CREATE PRIMARY KEY people (id)  
    190 go 
    191  
    192183CREATE TABLE readers ( 
    193184    id integer NOT NULL UNIQUE INDEX DEFAULT _rowid, 
    194185    post_id integer NOT NULL, 
  • activerecord/test/fixtures/db_definitions/oracle.drop.sql

    old new  
    1616drop table entrants; 
    1717drop table colnametests; 
    1818drop table mixins; 
    19 drop table people; 
    2019drop table readers; 
    2120drop table binaries; 
    2221drop table comments; 
     
    4948drop sequence entrants_seq; 
    5049drop sequence colnametests_seq; 
    5150drop sequence mixins_seq; 
    52 drop sequence people_seq; 
    5351drop sequence binaries_seq; 
    5452drop sequence posts_seq; 
    5553drop sequence comments_seq; 
  • activerecord/test/fixtures/db_definitions/oracle.sql

    old new  
    202202); 
    203203create sequence mixins_seq minvalue 10000; 
    204204 
    205 create table people ( 
    206     id integer not null, 
    207     first_name varchar(40) null, 
    208     lock_version integer default 0, 
    209     primary key (id) 
    210 ); 
    211 create sequence people_seq minvalue 10000; 
    212  
    213205create table readers ( 
    214206    id integer not null, 
    215207    post_id integer not null, 
  • activerecord/test/fixtures/db_definitions/postgresql.drop.sql

    old new  
    1616DROP TABLE entrants; 
    1717DROP TABLE colnametests; 
    1818DROP TABLE mixins; 
    19 DROP TABLE people; 
    2019DROP TABLE readers; 
    2120DROP TABLE binaries; 
    2221DROP TABLE computers; 
  • activerecord/test/fixtures/db_definitions/postgresql.sql

    old new  
    141141  updated_at timestamp 
    142142); 
    143143 
    144 CREATE TABLE people ( 
    145   id serial primary key, 
    146   first_name text, 
    147   lock_version integer default 0 
    148 ); 
    149  
    150144CREATE TABLE readers ( 
    151145    id serial primary key, 
    152146    post_id integer NOT NULL, 
  • activerecord/test/fixtures/db_definitions/schema.rb

    old new  
    99      ActiveRecord::Base.connection.execute "SET GENERATOR #{args.first}_seq TO 10000" 
    1010    end 
    1111  end 
     12   
     13  create_table :people, :force => true do |t| 
     14    t.string :first_name     
     15    t.lock_version 
     16  end 
    1217 
    1318  create_table :taggings, :force => true do |t| 
    1419    t.column :tag_id, :integer 
  • activerecord/test/fixtures/db_definitions/sqlite.drop.sql

    old new  
    1414DROP TABLE entrants; 
    1515DROP TABLE colnametests; 
    1616DROP TABLE mixins; 
    17 DROP TABLE people; 
    1817DROP TABLE readers; 
    1918DROP TABLE binaries; 
    2019DROP TABLE computers; 
  • activerecord/test/fixtures/db_definitions/sqlite.sql

    old new  
    117117  'updated_at' DATETIME DEFAULT NULL 
    118118); 
    119119 
    120 CREATE TABLE 'people' ( 
    121   'id' INTEGER NOT NULL PRIMARY KEY, 
    122   'first_name' VARCHAR(40) DEFAULT NULL, 
    123   'lock_version' INTEGER NOT NULL DEFAULT 0 
    124 ); 
    125  
    126120CREATE TABLE 'readers' ( 
    127121    'id' INTEGER NOT NULL PRIMARY KEY, 
    128122    'post_id' INTEGER NOT NULL, 
  • activerecord/test/fixtures/db_definitions/sybase.drop.sql

    old new  
    1414DROP TABLE entrants 
    1515DROP TABLE colnametests 
    1616DROP TABLE mixins 
    17 DROP TABLE people 
    1817DROP TABLE readers 
    1918DROP TABLE binaries 
    2019DROP TABLE computers 
  • activerecord/test/fixtures/db_definitions/sybase.sql

    old new  
    116116  type varchar(40) NULL 
    117117) 
    118118 
    119 CREATE TABLE people ( 
    120   id numeric(9,0) IDENTITY PRIMARY KEY, 
    121   first_name varchar(40) NULL, 
    122   lock_version int DEFAULT 0 
    123 ) 
    124  
    125119CREATE TABLE readers ( 
    126120    id numeric(9,0) IDENTITY PRIMARY KEY, 
    127121    post_id int NOT NULL,