Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

what I plan to build, ideas generorusly copied from ActiveRecord migr…

…ation documentation
  • Loading branch information...
commit d754da620c3cf88ef4929534fdb7be90202f8383 1 parent 378bb9b
RailsFactory authored May 24, 2012

Showing 1 changed file with 83 additions and 0 deletions. Show diff stats Hide diff stats

  1. 83  lib/migration.rb
83  lib/migration.rb
@@ -10,11 +10,31 @@ class Migration
10 10
 
11 11
 database.create_table(tablename, columns)
12 12
 database.drop_table(tablename)
  13
+database.rename_table(oldtable,newtable)
13 14
 database.rename_table(oldtablename, newtablename)
14 15
 database.action.to_sql
15 16
 
  17
+have a table migration in DB with one value
16 18
 
17 19
 
  20
+schema
  21
+
  22
+
  23
+column types
  24
+:binary
  25
+:boolean
  26
+:date
  27
+:datetime
  28
+:decimal
  29
+:float
  30
+:integer
  31
+:primary_key
  32
+:string
  33
+:text
  34
+:time
  35
+:timestamp
  36
+
  37
+migration version numbers
18 38
 
19 39
 table.add_column(columnname,type, constraint)
20 40
 table.remove_column(columnname)
@@ -26,9 +46,72 @@ class Migration
26 46
 table.action.to_sql
27 47
 
28 48
 
  49
+default fields
  50
+id
  51
+timestamps
  52
+
  53
+rails activerecord examples
  54
+
  55
+add_column :accounts, :ssl_enabled, :boolean, :default => 1
  56
+
  57
+remove_column :accounts, :ssl_enabled
  58
+
  59
+
  60
+class AddSystemSettings < ActiveRecord::Migration
  61
+  def up
  62
+    create_table :system_settings do |t|
  63
+      t.string  :name
  64
+      t.string  :label
  65
+      t.text    :value
  66
+      t.string  :type
  67
+      t.integer :position
  68
+    end
  69
+
  70
+    SystemSetting.create  :name => "notice",
  71
+                          :label => "Use notice?",
  72
+                          :value => 1
  73
+  end
  74
+
  75
+  def down
  76
+    drop_table :system_settings
  77
+  end
  78
+end
  79
+
  80
+
  81
+create_table(name, options) Creates a table called name and makes the table object available to a block that can then add columns to it, following the same format as add_column. See example above. The options hash is for fragments like "DEFAULT CHARSET=UTF-8" that are appended to the create table definition.
  82
+
  83
+drop_table(name): Drops the table called name.
  84
+
  85
+rename_table(old_name, new_name): Renames the table called old_name to new_name.
  86
+
  87
+add_column(table_name, column_name, type, options): Adds a new column to the table called table_name named column_name specified to be one of the following types: :string, :text, :integer, :float, :decimal, :datetime, :timestamp, :time, :date, :binary, :boolean. A default value can be specified by passing an options hash like { :default => 11 }. Other options include :limit and :null (e.g. { :limit => 50, :null => false }) -- see ActiveRecord::ConnectionAdapters::TableDefinition#column for details.
  88
+
  89
+rename_column(table_name, column_name, new_column_name): Renames a column but keeps the type and content.
  90
+
  91
+change_column(table_name, column_name, type, options): Changes the column to a different type using the same parameters as add_column.
  92
+
  93
+remove_column(table_name, column_names): Removes the column listed in column_names from the table called table_name.
  94
+
  95
+add_index(table_name, column_names, options): Adds a new index with the name of the column. Other options include :name, :unique (e.g. { :name => "users_name_index", :unique => true }) and :order (e.g. { :order => {:name => :desc} }</tt>).
  96
+
  97
+remove_index(table_name, :column => column_name): Removes the index specified by column_name.
  98
+
  99
+remove_index(table_name, :name => index_name): Removes the index specified by index_name.
  100
+
29 101
 
30 102
 
31 103
 
  104
+A migration is a subclass of ActiveRecord::Migration that implements two methods: up (perform the required transformations) and down (revert them).
32 105
 
  106
+Active Record provides methods that perform common data definition tasks in a database independent way 
33 107
 
  108
+add_column
  109
+add_index
  110
+change_column
  111
+change_table
  112
+create_table
  113
+drop_table
  114
+remove_column
  115
+remove_index
  116
+rename_column
34 117
 =end  

0 notes on commit d754da6

Please sign in to comment.
Something went wrong with that request. Please try again.