activerecord_worm_table 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/VERSION +1 -1
  2. data/lib/activerecord_worm_table.rb +7 -1
  3. metadata +1 -1
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.2.0
@@ -1,3 +1,5 @@
1
+ require 'active_record'
2
+
1
3
  # implements a write-once-read-many table, wherein there is a
2
4
  # currently active version of a table, one or more historical
3
5
  # versions and a working version. modifications are made
@@ -61,7 +63,11 @@ module ActiveRecord
61
63
  def dup_table_schema(from, to)
62
64
  connection.execute( "drop table if exists #{to}")
63
65
  ct = connection.select_one( "show create table #{from}")["Create Table"]
64
- new_ct = ct.gsub( /CREATE TABLE `#{from}`/, "CREATE TABLE `#{to}`")
66
+ ct_no_constraint_names = ct.gsub(/CONSTRAINT `[^`]*`/, "CONSTRAINT ``")
67
+ i = 0
68
+ ct_uniq_constraint_names = ct_no_constraint_names.gsub(/CONSTRAINT ``/) { |s| i+=1 ; "CONSTRAINT `#{to}_#{i}`" }
69
+
70
+ new_ct = ct_uniq_constraint_names.gsub( /CREATE TABLE `#{from}`/, "CREATE TABLE `#{to}`")
65
71
  connection.execute(new_ct)
66
72
  end
67
73
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_worm_table
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - mccraig mccraig of the clan mccraig