Module: ActiveRecord::ConnectionAdapters::SchemaStatements
- Defined in:
- lib/cms/extensions/active_record/connection_adapters/abstract/schema_statements.rb
Instance Method Summary collapse
-
#add_content_column(table_name, column_name, type, options = {}) ⇒ Object
Adds a column to both the primary and versioned table.
-
#create_content_table(table_name, options = {}) {|t| ... } ⇒ Object
(also: #create_versioned_table)
Pass in “:versioned => false” in the options hash to create a non-versioned table.
- #create_table_from_definition(table_name, options, table_definition) ⇒ Object
- #drop_versioned_table(table_name) ⇒ Object
Instance Method Details
#add_content_column(table_name, column_name, type, options = {}) ⇒ Object
Adds a column to both the primary and versioned table. Save needing two calls. This is only needed if your content block is versioned, otherwise add_column will work just fine.
82 83 84 85 |
# File 'lib/cms/extensions/active_record/connection_adapters/abstract/schema_statements.rb', line 82 def add_content_column(table_name, column_name, type, ={}) add_column table_name, column_name, type, add_column "#{table_name.to_s.singularize}_versions".to_sym, column_name, type, end |
#create_content_table(table_name, options = {}) {|t| ... } ⇒ Object Also known as: create_versioned_table
Pass in “:versioned => false” in the options hash to create a non-versioned table.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/cms/extensions/active_record/connection_adapters/abstract/schema_statements.rb', line 6 def create_content_table(table_name, ={}, &block) #Do the primary table t = TableDefinition.new(self) t.primary_key([:primary_key] || Base.get_primary_key(table_name)) unless [:id] == false unless [:versioned] == false t.integer :version t.integer :lock_version, :default => 0 end yield t # Blocks currently must have a name column, otherwise the UI fails in several places. # Some migrations may have already specified a name attribute, so we don't want to overwrite it here. t.string :name unless t[:name] t.boolean :published, :default => false t.boolean :deleted, :default => false t.boolean :archived, :default => false t.integer :created_by_id t.integer :updated_by_id t. create_table_from_definition(table_name, , t) unless [:versioned] == false #Do the versions table vt = TableDefinition.new(self) vt.primary_key([:primary_key] || Base.get_primary_key(table_name)) unless [:id] == false vt.integer "#{table_name.to_s.singularize}_id".to_sym vt.integer :version yield vt # Create implicit name column in version table as well. vt.string :name unless vt[:name] vt.boolean :published, :default => false vt.boolean :deleted, :default => false vt.boolean :archived, :default => false vt.string :version_comment vt.integer :created_by_id vt.integer :updated_by_id vt. create_table_from_definition("#{table_name.to_s.singularize}_versions".to_sym, , vt) end end |
#create_table_from_definition(table_name, options, table_definition) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/cms/extensions/active_record/connection_adapters/abstract/schema_statements.rb', line 63 def create_table_from_definition(table_name, , table_definition) if [:force] && table_exists?(table_name) drop_table(table_name, ) end create_sql = "CREATE#{' TEMPORARY' if [:temporary]} TABLE " create_sql << "#{quote_table_name(table_name)} (" create_sql << table_definition.to_sql create_sql << ") #{[:options]}" execute create_sql end |
#drop_versioned_table(table_name) ⇒ Object
75 76 77 78 |
# File 'lib/cms/extensions/active_record/connection_adapters/abstract/schema_statements.rb', line 75 def drop_versioned_table(table_name) drop_table "#{table_name.singularize}_versions".to_sym drop_table table_name end |