Class: LayoutModelMigration

Inherits:
Migration
  • Object
show all
Defined in:
lib/migrations/yodel/03_layout_model.rb

Class Method Summary collapse

Class Method Details

.down(site) ⇒ Object



33
34
35
36
37
# File 'lib/migrations/yodel/03_layout_model.rb', line 33

def self.down(site)
  site.layouts.destroy
  site.persistent_layouts.destroy
  site.file_layouts.destroy
end

.up(site) ⇒ Object



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
# File 'lib/migrations/yodel/03_layout_model.rb', line 2

def self.up(site)
  site.records.create_model :layouts do |layouts|
    add_field :name, :string, validations: {required: {}}, index: true
    add_field :mime_type, :string, validations: {required: {}}, index: true
    
    layouts.allowed_children = []
    layouts.allowed_parents = []
    layouts.searchable = false
    layouts.record_class_name = 'Layout'
  end
  
  site.layouts.create_model :persistent_layouts do |persistent_layouts|
    add_field :markup, :html, validations: {required: {}}
    add_many  :pages, foreign_key: 'page_layout_record'
    
    persistent_layouts.allowed_children = [persistent_layouts]
    persistent_layouts.allowed_parents = [persistent_layouts]
    persistent_layouts.searchable = false
    persistent_layouts.record_class_name = 'PersistentLayout'
  end
  
  site.layouts.create_model :file_layouts do |file_layouts|
    add_field :path, :string, validations: {required: {}}
    
    file_layouts.allowed_children = [file_layouts]
    file_layouts.allowed_parents = [file_layouts]
    file_layouts.searchable = false
    file_layouts.record_class_name = 'FileLayout'
  end
end