Class: AddActiveRecordSurvey

Inherits:
ActiveRecord::Migration
  • Object
show all
Defined in:
lib/generators/active_record_survey/templates/migration_0.1.0.rb

Class Method Summary collapse

Class Method Details

.downObject



52
53
54
55
56
57
58
59
# File 'lib/generators/active_record_survey/templates/migration_0.1.0.rb', line 52

def self.down
	drop_table :active_record_surveys
	drop_table :active_record_survey_nodes
	drop_table :active_record_survey_node_validations
	drop_table :active_record_survey_node_maps
	drop_table :active_record_survey_instances
	drop_table :active_record_survey_instance_nodes
end

.upObject



2
3
4
5
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
# File 'lib/generators/active_record_survey/templates/migration_0.1.0.rb', line 2

def self.up
	create_table :active_record_surveys do |t|
		t.timestamps null: false
	end

	create_table :active_record_survey_nodes do |t|
		t.string :type

		t.timestamps null: false
	end

	create_table :active_record_survey_node_validations do |t|
		t.references :active_record_survey_node
		t.string :type
		t.string :value

		t.timestamps null: false
	end

	create_table :active_record_survey_node_maps do |t|
		t.references :active_record_survey_node

		# AwesomeNestedSet fields
		t.integer :parent_id, :null => true, :index => true
		t.integer :lft, :null => false, :index => true
		t.integer :rgt, :null => false, :index => true

		# optional fields
		t.integer :depth, :null => false, :default => 0
		t.integer :children_count, :null => false, :default => 0

		t.references :active_record_survey

		t.timestamps null: false
	end

	create_table :active_record_survey_instances do |t|
		t.references :active_record_survey

		t.timestamps null: false
	end
	create_table :active_record_survey_instance_nodes do |t|
		t.references :active_record_survey_instance
		t.references :active_record_survey_node
		t.string :value

		t.timestamps null: false
	end
end