landable 1.13.1 → 1.13.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (175) hide show
  1. data/.rubocop.yml +281 -0
  2. data/.travis.yml +0 -1
  3. data/CHANGELOG.md +5 -1
  4. data/Gemfile +3 -4
  5. data/README.md +2 -0
  6. data/Rakefile +6 -3
  7. data/app/controllers/concerns/landable/variables_concern.rb +9 -9
  8. data/app/controllers/landable/api/access_tokens_controller.rb +7 -8
  9. data/app/controllers/landable/api/assets_controller.rb +29 -26
  10. data/app/controllers/landable/api/audits_controller.rb +6 -5
  11. data/app/controllers/landable/api/configurations_controller.rb +1 -1
  12. data/app/controllers/landable/api/directories_controller.rb +2 -2
  13. data/app/controllers/landable/api/page_revisions_controller.rb +2 -4
  14. data/app/controllers/landable/api/pages_controller.rb +39 -40
  15. data/app/controllers/landable/api/template_revisions_controller.rb +1 -2
  16. data/app/controllers/landable/api/templates_controller.rb +15 -14
  17. data/app/controllers/landable/api/themes_controller.rb +15 -14
  18. data/app/controllers/landable/api_controller.rb +10 -11
  19. data/app/controllers/landable/public/pages_controller.rb +2 -2
  20. data/app/controllers/landable/public/preview/page_revisions_controller.rb +2 -2
  21. data/app/controllers/landable/public/preview/pages_controller.rb +1 -1
  22. data/app/controllers/landable/public/sitemap_controller.rb +2 -2
  23. data/app/decorators/landable/page_decorator.rb +3 -3
  24. data/app/helpers/landable/pages_helper.rb +2 -2
  25. data/app/helpers/landable/traffic_helper.rb +2 -4
  26. data/app/models/concerns/landable/has_assets.rb +6 -9
  27. data/app/models/concerns/landable/has_templates.rb +6 -7
  28. data/app/models/concerns/landable/librarian.rb +5 -5
  29. data/app/models/concerns/landable/table_name.rb +2 -2
  30. data/app/models/landable/access_token.rb +1 -1
  31. data/app/models/landable/asset.rb +8 -8
  32. data/app/models/landable/asset_search_engine.rb +7 -8
  33. data/app/models/landable/author.rb +2 -1
  34. data/app/models/landable/category.rb +1 -3
  35. data/app/models/landable/directory.rb +2 -2
  36. data/app/models/landable/page.rb +44 -50
  37. data/app/models/landable/page_revision.rb +27 -41
  38. data/app/models/landable/page_search_engine.rb +5 -6
  39. data/app/models/landable/search_engine.rb +2 -2
  40. data/app/models/landable/template.rb +9 -11
  41. data/app/models/landable/template_revision.rb +4 -14
  42. data/app/models/landable/theme.rb +1 -1
  43. data/app/models/landable/traffic/attribution.rb +3 -1
  44. data/app/models/landable/traffic/page_view.rb +1 -1
  45. data/app/models/landable/traffic/user_agent.rb +1 -1
  46. data/app/models/landable/traffic/visit.rb +1 -1
  47. data/app/responders/landable/api_responder.rb +5 -3
  48. data/app/responders/landable/page_render_responder.rb +1 -1
  49. data/app/serializers/landable/asset_serializer.rb +1 -1
  50. data/app/serializers/landable/audit_serializer.rb +2 -3
  51. data/app/serializers/landable/directory_serializer.rb +2 -2
  52. data/app/serializers/landable/page_revision_serializer.rb +0 -1
  53. data/app/serializers/landable/page_serializer.rb +5 -5
  54. data/app/serializers/landable/template_serializer.rb +2 -2
  55. data/app/services/landable/authentication_service.rb +1 -1
  56. data/app/services/landable/registration_service.rb +3 -2
  57. data/app/services/landable/render_service.rb +16 -18
  58. data/app/services/landable/screenshot_service.rb +3 -4
  59. data/app/services/landable/tidy_service.rb +32 -37
  60. data/app/validators/path_validator.rb +1 -3
  61. data/app/validators/url_validator.rb +4 -7
  62. data/config/routes.rb +3 -6
  63. data/db/migrate/20130510221424_create_landable_schema.rb +45 -56
  64. data/db/migrate/20130909182713_landable_pages__add_updated_by.rb +2 -2
  65. data/db/migrate/20130909182715_landable_page_revisions__break_out_snapshot.rb +9 -12
  66. data/db/migrate/20131002220041_file_based_themes.rb +3 -3
  67. data/db/migrate/20131008164204_create_head_tag_on_page.rb +4 -4
  68. data/db/migrate/20131008193544_drop_status_codes_model.rb +1 -2
  69. data/db/migrate/20131028145652_add_traffic_schema.rb +5 -5
  70. data/db/migrate/20131101213623_add_dnt_column_to_visits.rb +1 -1
  71. data/db/migrate/20131106185946_add_index_on_page_revisions_path.rb +1 -1
  72. data/db/migrate/20131106193021_page_revisisons__path_status_code_index.rb +1 -1
  73. data/db/migrate/20131121150902_add_attribution_id_to_unique_index.rb +2 -2
  74. data/db/migrate/20131216214027_drop_browser_screenshot_tables.rb +3 -3
  75. data/db/migrate/20140128170659_file_backed_templates.rb +1 -1
  76. data/db/migrate/20140205193757_fix_status_codes.rb +3 -3
  77. data/db/migrate/20140220170324_add_slug_to_categories.rb +1 -1
  78. data/db/migrate/20140224205516_rename_traffic_schema.rb +7 -9
  79. data/db/migrate/20140509190128_create_template_revisions.rb +13 -15
  80. data/db/migrate/20140509192856_create_audits.rb +3 -3
  81. data/db/migrate/20140602213937_path_response_time_view.rb +20 -19
  82. data/features/step_definitions/asset_steps.rb +10 -12
  83. data/features/step_definitions/core_api_steps.rb +29 -27
  84. data/features/step_definitions/factory_steps.rb +16 -16
  85. data/features/step_definitions/html_steps.rb +1 -1
  86. data/features/step_definitions/liquid_steps.rb +8 -8
  87. data/features/step_definitions/theme_steps.rb +4 -4
  88. data/features/support/env.rb +5 -5
  89. data/landable.gemspec +2 -2
  90. data/lib/generators/landable/landable_generator.rb +2 -2
  91. data/lib/generators/templates/landable.rb +1 -1
  92. data/lib/landable.rb +7 -7
  93. data/lib/landable/configuration.rb +10 -19
  94. data/lib/landable/engine.rb +19 -19
  95. data/lib/landable/error.rb +1 -3
  96. data/lib/landable/layout.rb +6 -6
  97. data/lib/landable/liquid/asset_tags.rb +3 -5
  98. data/lib/landable/liquid/drops.rb +3 -8
  99. data/lib/landable/liquid/filters.rb +1 -3
  100. data/lib/landable/liquid/tags.rb +10 -10
  101. data/lib/landable/migration.rb +30 -30
  102. data/lib/landable/mime_types.rb +1 -1
  103. data/lib/landable/partial.rb +2 -2
  104. data/lib/landable/seeds.rb +3 -4
  105. data/lib/landable/traffic.rb +4 -8
  106. data/lib/landable/traffic/tracker.rb +48 -43
  107. data/lib/landable/traffic/user_tracker.rb +15 -10
  108. data/lib/landable/version.rb +1 -1
  109. data/lib/schema_moves.rb +15 -16
  110. data/lib/tasks/landable/cucumber.rake +46 -47
  111. data/lib/tasks/landable/data.rake +13 -14
  112. data/lib/tasks/landable/pgtap.rake +12 -18
  113. data/lib/tasks/landable/seed.rake +4 -4
  114. data/spec/concerns/landable/has_assets_spec.rb +15 -19
  115. data/spec/concerns/landable/has_templates_spec.rb +10 -13
  116. data/spec/concerns/landable/librarian.rb +4 -4
  117. data/spec/concerns/landable/table_name_spec.rb +3 -5
  118. data/spec/concerns/landable/traffic/table_name_spec.rb +2 -4
  119. data/spec/controllers/concerns/landable/variables_concern_spec.rb +11 -10
  120. data/spec/controllers/landable/api/assets_controller_spec.rb +15 -14
  121. data/spec/controllers/landable/api/audits_controller_spec.rb +104 -102
  122. data/spec/controllers/landable/api/categories_controller_spec.rb +36 -34
  123. data/spec/controllers/landable/api/configuration_controller_spec.rb +14 -12
  124. data/spec/controllers/landable/api/directories_controller_spec.rb +52 -50
  125. data/spec/controllers/landable/api/page_revisions_controller_spec.rb +20 -18
  126. data/spec/controllers/landable/api/pages_controller_spec.rb +204 -203
  127. data/spec/controllers/landable/api/template_revisions_controller_spec.rb +20 -18
  128. data/spec/controllers/landable/api/templates_controller_spec.rb +39 -37
  129. data/spec/controllers/landable/api_controller_spec.rb +24 -26
  130. data/spec/controllers/public/preview/page_revisions_controller_spec.rb +36 -34
  131. data/spec/controllers/public/preview/pages_controller_spec.rb +32 -30
  132. data/spec/controllers/public/sitemap_controller_spec.rb +19 -17
  133. data/spec/decorators/page_decorator_spec.rb +9 -9
  134. data/spec/dummy/app/helpers/application_helper.rb +1 -1
  135. data/spec/dummy/config/application.rb +5 -6
  136. data/spec/dummy/config/boot.rb +1 -1
  137. data/spec/dummy/config/environments/test.rb +1 -1
  138. data/spec/dummy/config/initializers/landable.rb +7 -6
  139. data/spec/factories/asset.rb +1 -1
  140. data/spec/factories/audit.rb +1 -1
  141. data/spec/factories/authors.rb +1 -1
  142. data/spec/factories/category.rb +1 -1
  143. data/spec/factories/pages.rb +4 -4
  144. data/spec/factories/template.rb +3 -3
  145. data/spec/factories/theme.rb +2 -2
  146. data/spec/helpers/pages_helper_spec.rb +5 -5
  147. data/spec/lib/landable/configuration_spec.rb +2 -4
  148. data/spec/lib/landable/event_publisher_spec.rb +1 -3
  149. data/spec/lib/landable/layout_spec.rb +4 -4
  150. data/spec/lib/landable/liquid_spec.rb +12 -14
  151. data/spec/lib/landable/migration_spec.rb +4 -4
  152. data/spec/lib/landable/partial_spec.rb +18 -18
  153. data/spec/lib/landable/tracking_spec.rb +27 -29
  154. data/spec/lib/landable/traffic_spec.rb +29 -33
  155. data/spec/models/landable/access_token_spec.rb +1 -1
  156. data/spec/models/landable/asset_spec.rb +9 -11
  157. data/spec/models/landable/directory_spec.rb +7 -7
  158. data/spec/models/landable/page/errors_spec.rb +1 -3
  159. data/spec/models/landable/page_revision_spec.rb +23 -24
  160. data/spec/models/landable/page_spec.rb +41 -42
  161. data/spec/models/landable/template_revision_spec.rb +3 -3
  162. data/spec/models/landable/template_spec.rb +11 -11
  163. data/spec/models/landable/theme_spec.rb +2 -2
  164. data/spec/models/landable/traffic/referer_spec.rb +3 -3
  165. data/spec/responders/page_render_responder_spec.rb +0 -2
  166. data/spec/routing/public_page_route_spec.rb +4 -5
  167. data/spec/services/landable/authentication_service_spec.rb +7 -7
  168. data/spec/services/landable/render_service_spec.rb +8 -8
  169. data/spec/services/landable/screenshot_service_spec.rb +3 -3
  170. data/spec/services/landable/tidy_service_spec.rb +20 -20
  171. data/spec/spec_helper.rb +3 -3
  172. data/spec/support/behaviors.rb +4 -4
  173. data/spec/support/helpers.rb +1 -1
  174. metadata +86 -35
  175. checksums.yaml +0 -7
@@ -5,8 +5,8 @@ module Landable
5
5
  class Error < StandardError; end
6
6
 
7
7
  class << self
8
- def capture url
9
- if not Landable.configuration.publicist_url
8
+ def capture(url)
9
+ if !Landable.configuration.publicist_url
10
10
  Rails.logger.warn "Couldn't generate screenshot for #{url}; no Landable.configuration.publicist_url configured"
11
11
  else
12
12
  screenshots_uri = URI(Landable.configuration.publicist_url)
@@ -22,11 +22,10 @@ module Landable
22
22
 
23
23
  file
24
24
  else
25
- raise Error, "Received #{response.code} back from #{screenshots_uri.to_s}"
25
+ fail Error, "Received #{response.code} back from #{screenshots_uri}"
26
26
  end
27
27
  end
28
28
  end
29
29
  end
30
-
31
30
  end
32
31
  end
@@ -1,10 +1,13 @@
1
1
  module Landable
2
2
  module TidyService
3
-
4
3
  class TidyError < StandardError; end
5
4
 
6
- mattr_accessor :options
7
- @@options = [
5
+ class << self
6
+ attr_accessor :options
7
+ attr_accessor :liquid_elements
8
+ end
9
+
10
+ @options = [
8
11
  # is what we have
9
12
  '-utf8',
10
13
 
@@ -31,28 +34,21 @@ module Landable
31
34
 
32
35
  # silence will fall
33
36
  '--quiet true',
34
- '--show-warnings false',
37
+ '--show-warnings false'
35
38
  ]
36
39
 
37
40
  # list of liquid tags that also render tags - things that we should
38
41
  # consider to be element-level, and therefore to be tidied along with the
39
42
  # rest of the dom
40
- mattr_accessor :liquid_elements
41
- @@liquid_elements = [
42
- 'template',
43
- 'title_tag',
44
- 'meta_tags',
45
- 'img_tag',
46
- ]
47
-
43
+ @liquid_elements = %w(template title_tag meta_tags img_tag)
48
44
 
49
- def self.call! input
50
- self.call input, raise_on_error: true
45
+ def self.call!(input)
46
+ call input, raise_on_error: true
51
47
  end
52
48
 
53
- def self.call input, runtime_options={}
54
- if not tidyable?
55
- raise TidyError, 'Your system doesn\'t seem to have tidy installed. Please see https://github.com/w3c/tidy-html5.'
49
+ def self.call(input, runtime_options = {})
50
+ unless tidyable?
51
+ fail TidyError, 'Your system doesn\'t seem to have tidy installed. Please see https://github.com/w3c/tidy-html5.'
56
52
  end
57
53
 
58
54
  # wrapping known liquid in a span to allow tidy to format them nicely
@@ -70,8 +66,8 @@ module Landable
70
66
  # 2: error
71
67
  # 3: ???
72
68
  # 4: profit
73
- if $?.exitstatus >= 2 and runtime_options[:raise_on_error]
74
- raise TidyError, "Tidy exited with status #{$?} - check stderr."
69
+ if $CHILD_STATUS.exitstatus >= 2 && runtime_options[:raise_on_error]
70
+ fail TidyError, "Tidy exited with status #{$CHILD_STATUS} - check stderr."
75
71
  end
76
72
 
77
73
  # unnwrapping the liquid that we wrapped earlier
@@ -82,12 +78,12 @@ module Landable
82
78
  end
83
79
 
84
80
  def self.tidyable?
85
- @@is_tidyable ||= Kernel.system('which tidy > /dev/null')
81
+ @is_tidyable ||= Kernel.system('which tidy > /dev/null')
86
82
  end
87
83
 
88
84
  protected
89
85
 
90
- def self.wrap_liquid input
86
+ def self.wrap_liquid(input)
91
87
  output = input.dup
92
88
 
93
89
  output.scan(/(\s*(\{% *(?:#{liquid_elements.join('|')}) *.*?%})\s*)/).each do |match, liquid|
@@ -100,10 +96,10 @@ module Landable
100
96
  output
101
97
  end
102
98
 
103
- def self.unwrap_liquid input
99
+ def self.unwrap_liquid(input)
104
100
  output = input.dup
105
101
 
106
- output.scan(/(<div data-liquid="(.*?)"><\/div>)/).each do |match, liquid|
102
+ output.scan(%r{(<div data-liquid="(.*?)"><\/div>)}).each do |match, liquid|
107
103
  # ensure we match utf8 for utf8
108
104
  decoded = Base64.decode64(liquid).force_encoding(match.encoding)
109
105
  output.gsub! match, decoded
@@ -112,9 +108,8 @@ module Landable
112
108
  output
113
109
  end
114
110
 
115
-
116
111
  class Result < Object
117
- def initialize source
112
+ def initialize(source)
118
113
  @source = source
119
114
  end
120
115
 
@@ -123,33 +118,33 @@ module Landable
123
118
  end
124
119
 
125
120
  def body
126
- if match = @source.match(/<body(?: [^>]*)?>(.*)<\/body>/m)
127
- deindent match[1]
128
- end
121
+ match = @source.match(%r{<body(?: [^>]*)?>(.*)<\/body>}m)
122
+ return unless match
123
+ deindent match[1]
129
124
  end
130
125
 
131
126
  def head
132
- if match = @source.match(/<head>(.*)<\/head>/m)
133
- deindent match[1]
134
- end
127
+ match = @source.match(%r{<head>(.*)<\/head>}m)
128
+ return unless match
129
+ deindent match[1]
135
130
  end
136
131
 
137
132
  def css
138
- links = head.try :scan, /<link [^>]*type=['"]text\/css['"][^>]*>/
139
- styles = head.try :scan, /<style[^>]*>.*?<\/style>/m
133
+ links = head.try :scan, %r{<link [^>]*type=['"]text\/css['"][^>]*>}
134
+ styles = head.try :scan, %r{<style[^>]*>.*?<\/style>}m
140
135
  [links.to_a, styles.to_a].flatten.join("\n\n")
141
136
  end
142
137
 
143
138
  protected
144
139
 
145
- def deindent string
146
- if match = string.match(/^([ \t]*)[^\s]/)
140
+ def deindent(string)
141
+ match = string.match(/^([ \t]*)[^\s]/)
142
+ if match
147
143
  string.gsub(/^#{match[1]}/, '').strip
148
144
  else
149
145
  string.strip
150
146
  end
151
147
  end
152
148
  end
153
-
154
149
  end
155
- end
150
+ end
@@ -1,8 +1,6 @@
1
1
  class PathValidator < ActiveModel::Validator
2
2
  def validate(record)
3
- if match?(record.path)
4
- record.errors[:path] << "is Reserved!"
5
- end
3
+ record.errors[:path] << 'is Reserved!' if match?(record.path)
6
4
  end
7
5
 
8
6
  def match?(path)
@@ -1,13 +1,10 @@
1
1
  class UrlValidator < ActiveModel::EachValidator
2
-
3
2
  def validate_each(record, attribute, value)
4
3
  valid = begin
5
- value =~ /^[a-z]+\:\/\// or value =~ /^\//
4
+ value =~ %r{^[a-z]+\:\/\/} || value =~ %r{^\/}
6
5
  end
6
+ return if valid
7
7
 
8
- unless valid
9
- record.errors[attribute] << ("Invalid URL! Make sure it starts with http:// or /")
10
- end
8
+ record.errors[attribute] << ('Invalid URL! Make sure it starts with http:// or /')
11
9
  end
12
-
13
- end
10
+ end
data/config/routes.rb CHANGED
@@ -4,7 +4,7 @@ Landable::Engine.routes.draw do
4
4
  resources :categories, only: [:index, :show]
5
5
 
6
6
  resources :directories, only: [:index, :show], constraints: {
7
- id: /[%a-zA-Z0-9\/_.~-]*/
7
+ id: %r{[%a-zA-Z0-9\/_.~-]*}
8
8
  }
9
9
 
10
10
  resources :assets, only: [:index, :show, :create, :update, :deactivate, :destroy]
@@ -50,7 +50,6 @@ Landable::Engine.routes.draw do
50
50
 
51
51
  resources :access_tokens, only: [:create, :destroy, :show]
52
52
 
53
-
54
53
  # coming soon: screenshots!
55
54
 
56
55
  # resources :screenshots, only: [:index, :show, :create] do
@@ -69,9 +68,7 @@ Landable::Engine.routes.draw do
69
68
 
70
69
  get '/sitemap.xml' => 'sitemap#index', as: :sitemap
71
70
 
72
- get '*url' => 'pages#show', as: :page, format: false, constraints: lambda { |request|
73
- # Published Landable Page
74
- Landable::PageRevision.table_exists? && Landable::PageRevision.where(path: request.path, is_published: true).any?
75
- }
71
+ constraint = ->(request) { Landable::PageRevision.table_exists? && Landable::PageRevision.where(path: request.path, is_published: true).any? }
72
+ get '*url' => 'pages#show', as: :page, format: false, constraints: constraint
76
73
  end
77
74
  end
@@ -3,21 +3,20 @@ class CreateLandableSchema < Landable::Migration
3
3
  # This really should not be in this migration, but it's a convenient location
4
4
  # while everything's still under development.
5
5
  #
6
- # TODO extract to a separate migration, check if it exists, maybe check if we
6
+ # TODO: extract to a separate migration, check if it exists, maybe check if we
7
7
  # actually have permission to do it, etc.
8
8
  execute 'CREATE EXTENSION "uuid-ossp";'
9
- enable_extension "uuid-ossp"
10
- enable_extension "hstore"
11
- enable_extension "pg_trgm"
9
+ enable_extension 'uuid-ossp'
10
+ enable_extension 'hstore'
11
+ enable_extension 'pg_trgm'
12
12
 
13
13
  execute 'ALTER EXTENSION "uuid-ossp" SET SCHEMA "public";'
14
14
  execute "CREATE SCHEMA #{Landable.configuration.database_schema_prefix}landable;"
15
15
 
16
-
17
16
  ## status_codes
18
17
 
19
18
  create_table "#{Landable.configuration.database_schema_prefix}landable.status_code_categories", id: :uuid, primary_key: :status_code_category_id do |t|
20
- t.text :name, null: false
19
+ t.text :name, null: false
21
20
  end
22
21
 
23
22
  execute "CREATE UNIQUE INDEX #{Landable.configuration.database_schema_prefix}landable_status_code_categories__u_name ON #{Landable.configuration.database_schema_prefix}landable.status_code_categories(lower(name))"
@@ -25,9 +24,9 @@ class CreateLandableSchema < Landable::Migration
25
24
  $$Categories that status codes belong to. Used to affect behavior when viewing a page.$$"
26
25
 
27
26
  create_table "#{Landable.configuration.database_schema_prefix}landable.status_codes", id: :uuid, primary_key: :status_code_id do |t|
28
- t.uuid :status_code_category_id, null: false
29
- t.integer :code, null: false, limit: 2 # Creates as smallint
30
- t.text :description, null: false
27
+ t.uuid :status_code_category_id, null: false
28
+ t.integer :code, null: false, limit: 2 # Creates as smallint
29
+ t.text :description, null: false
31
30
  end
32
31
 
33
32
  execute "CREATE UNIQUE INDEX #{Landable.configuration.database_schema_prefix}landable_status_codes__u_code ON #{Landable.configuration.database_schema_prefix}landable.status_codes(code)"
@@ -35,7 +34,6 @@ class CreateLandableSchema < Landable::Migration
35
34
  execute "COMMENT ON TABLE #{Landable.configuration.database_schema_prefix}landable.status_codes IS
36
35
  $$Allowed status codes that pages can be set to.$$"
37
36
 
38
-
39
37
  ## themes
40
38
 
41
39
  create_table "#{Landable.configuration.database_schema_prefix}landable.themes", id: :uuid, primary_key: :theme_id do |t|
@@ -50,7 +48,6 @@ class CreateLandableSchema < Landable::Migration
50
48
  execute "COMMENT ON TABLE #{Landable.configuration.database_schema_prefix}landable.themes IS
51
49
  $$Created themes to be consumed by pages. Themes supply formatting (css) rules and can supply header/footer content as well.$$"
52
50
 
53
-
54
51
  ## templates
55
52
 
56
53
  create_table "#{Landable.configuration.database_schema_prefix}landable.templates", id: :uuid, primary_key: :template_id do |t|
@@ -65,28 +62,28 @@ class CreateLandableSchema < Landable::Migration
65
62
 
66
63
  execute "CREATE UNIQUE INDEX #{Landable.configuration.database_schema_prefix}landable_templates__u_name ON #{Landable.configuration.database_schema_prefix}landable.templates(lower(name))"
67
64
  execute "COMMENT ON TABLE #{Landable.configuration.database_schema_prefix}landable.templates IS
68
- $$Created templates to be consumed by pages.
69
- A template can supply 'starter' code for a page.
65
+ $$Created templates to be consumed by pages.
66
+ A template can supply 'starter' code for a page.
70
67
  A template can also supply code to create elements on a page (sidebars, for example).$$"
71
68
 
72
69
  ## pages
73
70
 
74
71
  create_table "#{Landable.configuration.database_schema_prefix}landable.pages", id: :uuid, primary_key: :page_id do |t|
75
- t.uuid :published_revision_id
76
- t.boolean :is_publishable, null: false, default: true
72
+ t.uuid :published_revision_id
73
+ t.boolean :is_publishable, null: false, default: true
77
74
 
78
- t.uuid :theme_id
79
- t.uuid :category_id
80
- t.uuid :status_code_id, null: false
75
+ t.uuid :theme_id
76
+ t.uuid :category_id
77
+ t.uuid :status_code_id, null: false
81
78
 
82
- t.text :path, null: false
79
+ t.text :path, null: false
83
80
 
84
- t.text :title
85
- t.text :body
81
+ t.text :title
82
+ t.text :body
86
83
 
87
- t.text :redirect_url
84
+ t.text :redirect_url
88
85
 
89
- t.hstore :meta_tags
86
+ t.hstore :meta_tags
90
87
 
91
88
  t.timestamp :imported_at
92
89
  t.timestamps
@@ -123,11 +120,10 @@ class CreateLandableSchema < Landable::Migration
123
120
  execute "COMMENT ON TABLE #{Landable.configuration.database_schema_prefix}landable.authors IS
124
121
  $$A list of authors that have accessed the website. Feeds foreign keys so we know which authors have published pages and updated assets.$$"
125
122
 
126
-
127
123
  ## access_tokens
128
124
 
129
125
  create_table "#{Landable.configuration.database_schema_prefix}landable.access_tokens", id: :uuid, primary_key: :access_token_id do |t|
130
- t.uuid :author_id, null: false
126
+ t.uuid :author_id, null: false
131
127
  t.timestamp :expires_at, null: false
132
128
  t.timestamps
133
129
  end
@@ -137,19 +133,18 @@ class CreateLandableSchema < Landable::Migration
137
133
  execute "COMMENT ON TABLE #{Landable.configuration.database_schema_prefix}landable.access_tokens IS
138
134
  $$Access tokens provide authentication information for specific users.$$"
139
135
 
140
-
141
136
  ## page_revisions
142
137
 
143
138
  create_table "#{Landable.configuration.database_schema_prefix}landable.page_revisions", id: :uuid, primary_key: :page_revision_id do |t|
144
- t.integer :ordinal
145
- t.text :notes
146
- t.boolean :is_minor, default: false
147
- t.boolean :is_published, default: true
139
+ t.integer :ordinal
140
+ t.text :notes
141
+ t.boolean :is_minor, default: false
142
+ t.boolean :is_published, default: true
148
143
 
149
- t.uuid :page_id, null: false
150
- t.uuid :author_id, null: false
144
+ t.uuid :page_id, null: false
145
+ t.uuid :author_id, null: false
151
146
 
152
- t.text :snapshot_attributes, null: false
147
+ t.text :snapshot_attributes, null: false
153
148
 
154
149
  t.timestamps
155
150
  end
@@ -159,12 +154,11 @@ class CreateLandableSchema < Landable::Migration
159
154
  The attributes of the page at the time of publishing are stored in snapshot_attributes, as essentially a text representation of a hash.
160
155
  The current/active/live revision can be identified by referring to its corresponding PAGES record, OR by looking for the max(ordinal) for a given page_id.$$"
161
156
 
162
-
163
157
  ## categories
164
158
 
165
159
  create_table "#{Landable.configuration.database_schema_prefix}landable.categories", id: :uuid, primary_key: :category_id do |t|
166
- t.text :name
167
- t.text :description
160
+ t.text :name
161
+ t.text :description
168
162
  end
169
163
 
170
164
  execute "CREATE UNIQUE INDEX #{Landable.configuration.database_schema_prefix}landable_categories__u_name ON #{Landable.configuration.database_schema_prefix}landable.categories(lower(name))"
@@ -172,16 +166,15 @@ class CreateLandableSchema < Landable::Migration
172
166
  $$Categories are used to sort pages.
173
167
  Examples could include SEO, PPC.$$"
174
168
 
175
-
176
169
  ## assets
177
170
 
178
171
  create_table "#{Landable.configuration.database_schema_prefix}landable.assets", id: :uuid, primary_key: :asset_id do |t|
179
- t.uuid :author_id, null: false
180
- t.text :name, null: false
181
- t.text :description
182
- t.text :data, null: false
183
- t.text :md5sum, null: false, length: 32
184
- t.text :mime_type, null: false
172
+ t.uuid :author_id, null: false
173
+ t.text :name, null: false
174
+ t.text :description
175
+ t.text :data, null: false
176
+ t.text :md5sum, null: false, length: 32
177
+ t.text :mime_type, null: false
185
178
  t.integer :file_size
186
179
  t.timestamps
187
180
  end
@@ -197,7 +190,6 @@ class CreateLandableSchema < Landable::Migration
197
190
  Examples of assets include images (jpg, png, gif) and documents (PDF).
198
191
  data, md5sum, mime_type, file_size are populated via the rails gem CarrierWave when a record is created.$$"
199
192
 
200
-
201
193
  ## browsers
202
194
 
203
195
  create_table "#{Landable.configuration.database_schema_prefix}landable.browsers", id: :uuid, primary_key: :browser_id do |t|
@@ -215,7 +207,6 @@ class CreateLandableSchema < Landable::Migration
215
207
 
216
208
  execute "CREATE INDEX #{Landable.configuration.database_schema_prefix}landable_screenshots__device_browser_browser_version ON #{Landable.configuration.database_schema_prefix}landable.browsers(device, browser, browser_version)"
217
209
 
218
-
219
210
  ## screenshots
220
211
 
221
212
  create_table "#{Landable.configuration.database_schema_prefix}landable.screenshots", id: :uuid, primary_key: :screenshot_id do |t|
@@ -241,7 +232,6 @@ class CreateLandableSchema < Landable::Migration
241
232
  execute "COMMENT ON TABLE #{Landable.configuration.database_schema_prefix}landable.screenshots IS
242
233
  $$Stores saved screenshots (taken of pages) and the URLs to retrieve the actual image.$$"
243
234
 
244
-
245
235
  ## asset associations table
246
236
 
247
237
  create_table "#{Landable.configuration.database_schema_prefix}landable.page_assets", id: :uuid, primary_key: :page_asset_id do |t|
@@ -305,9 +295,9 @@ class CreateLandableSchema < Landable::Migration
305
295
  $TRIGGER$
306
296
  LANGUAGE plpgsql;"
307
297
 
308
- execute "CREATE TRIGGER #{Landable.configuration.database_schema_prefix}landable_page_revisions__bfr_insert
309
- BEFORE INSERT ON #{Landable.configuration.database_schema_prefix}landable.page_revisions
310
- FOR EACH ROW EXECUTE PROCEDURE #{Landable.configuration.database_schema_prefix}landable.pages_revision_ordinal();"
298
+ execute "CREATE TRIGGER #{Landable.configuration.database_schema_prefix}landable_page_revisions__bfr_insert
299
+ BEFORE INSERT ON #{Landable.configuration.database_schema_prefix}landable.page_revisions
300
+ FOR EACH ROW EXECUTE PROCEDURE #{Landable.configuration.database_schema_prefix}landable.pages_revision_ordinal();"
311
301
 
312
302
  # Trigger disallowing deletes on page_revisions
313
303
  execute "CREATE FUNCTION #{Landable.configuration.database_schema_prefix}landable.tg_disallow()
@@ -328,13 +318,12 @@ class CreateLandableSchema < Landable::Migration
328
318
  $TRIGGER$
329
319
  LANGUAGE plpgsql;"
330
320
 
331
- execute "CREATE TRIGGER #{Landable.configuration.database_schema_prefix}landable_page_revisions__no_delete
332
- BEFORE DELETE ON #{Landable.configuration.database_schema_prefix}landable.page_revisions
333
- FOR EACH STATEMENT EXECUTE PROCEDURE #{Landable.configuration.database_schema_prefix}landable.tg_disallow();"
334
-
335
- execute "CREATE TRIGGER #{Landable.configuration.database_schema_prefix}landable_page_revisions__no_update
336
- BEFORE UPDATE OF notes, is_minor, page_id, author_id, created_at, ordinal ON #{Landable.configuration.database_schema_prefix}landable.page_revisions
337
- FOR EACH STATEMENT EXECUTE PROCEDURE #{Landable.configuration.database_schema_prefix}landable.tg_disallow();"
321
+ execute "CREATE TRIGGER #{Landable.configuration.database_schema_prefix}landable_page_revisions__no_delete
322
+ BEFORE DELETE ON #{Landable.configuration.database_schema_prefix}landable.page_revisions
323
+ FOR EACH STATEMENT EXECUTE PROCEDURE #{Landable.configuration.database_schema_prefix}landable.tg_disallow();"
338
324
 
325
+ execute "CREATE TRIGGER #{Landable.configuration.database_schema_prefix}landable_page_revisions__no_update
326
+ BEFORE UPDATE OF notes, is_minor, page_id, author_id, created_at, ordinal ON #{Landable.configuration.database_schema_prefix}landable.page_revisions
327
+ FOR EACH STATEMENT EXECUTE PROCEDURE #{Landable.configuration.database_schema_prefix}landable.tg_disallow();"
339
328
  end
340
329
  end