lesli 5.1.12 → 5.1.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +3 -0
  3. data/app/assets/stylesheets/lesli/application.css +43 -3
  4. data/app/controllers/lesli/application_devise_controller.rb +9 -5
  5. data/app/controllers/lesli/application_lesli_controller.rb +31 -0
  6. data/app/controllers/lesli/items/attachments_controller.rb +200 -0
  7. data/app/controllers/lesli/items/discussions_controller.rb +94 -67
  8. data/app/controllers/lesli/items/tasks_controller.rb +132 -62
  9. data/app/controllers/lesli/roles_controller.rb +1 -6
  10. data/app/controllers/lesli/users_controller.rb +1 -5
  11. data/app/helpers/lesli/announcements_helper.rb +14 -0
  12. data/app/helpers/lesli/navigation_helper.rb +1 -1
  13. data/app/helpers/lesli/turbo_helper.rb +0 -18
  14. data/app/interfaces/lesli/responder_interface.rb +65 -38
  15. data/app/mailers/lesli/application_lesli_mailer.rb +34 -8
  16. data/app/models/concerns/lesli/account_initializer.rb +5 -37
  17. data/app/models/concerns/lesli/account_logs.rb +5 -16
  18. data/app/models/concerns/lesli/items/activities.rb +29 -33
  19. data/app/models/concerns/lesli/items/attachments.rb +88 -0
  20. data/app/models/concerns/lesli/items/discussions.rb +25 -11
  21. data/app/models/concerns/lesli/items/ownership.rb +27 -0
  22. data/app/models/concerns/lesli/items/tasks.rb +26 -6
  23. data/app/models/concerns/lesli/user_extensions.rb +8 -10
  24. data/app/models/lesli/account.rb +10 -14
  25. data/app/models/lesli/items/activity.rb +25 -2
  26. data/app/models/lesli/items/attachment.rb +117 -0
  27. data/app/models/lesli/items/discussion.rb +6 -2
  28. data/app/models/lesli/items/task.rb +3 -1
  29. data/app/models/lesli/role.rb +14 -2
  30. data/app/models/lesli/user.rb +19 -21
  31. data/app/operators/lesli/account_operator.rb +84 -0
  32. data/app/operators/lesli/resource_operator.rb +123 -0
  33. data/app/services/lesli/application_lesli_service.rb +33 -116
  34. data/app/services/lesli/resource_service.rb +12 -159
  35. data/app/services/lesli/role_service.rb +11 -229
  36. data/app/services/lesli/user_service.rb +37 -117
  37. data/app/views/lesli/abouts/welcome.html.erb +2 -5
  38. data/app/views/lesli/errors/not_found.html.erb +7 -21
  39. data/app/views/lesli/errors/unauthorized.html.erb +11 -27
  40. data/app/views/lesli/layouts/application-devise.html.erb +10 -9
  41. data/app/views/lesli/layouts/application-lesli.html.erb +2 -2
  42. data/app/views/lesli/partials/_application-lesli-announcements.html.erb +28 -0
  43. data/app/views/lesli/partials/_application-lesli-assets.html.erb +3 -3
  44. data/app/views/lesli/partials/_application-lesli-header.html.erb +8 -11
  45. data/app/views/lesli/partials/_application-lesli-turbo.html.erb +5 -0
  46. data/config/initializers/lesli.rb +10 -2
  47. data/config/locales/translations.en.yml +57 -14
  48. data/config/locales/translations.es.yml +55 -11
  49. data/db/migrate/v1/0000000210_create_lesli_users.rb +1 -0
  50. data/db/seed/accounts.rb +5 -5
  51. data/db/seed/users.rb +8 -16
  52. data/db/seed/xyz.rb +36 -17
  53. data/lib/generators/lesli/base_generator.rb +41 -3
  54. data/lib/generators/lesli/controller/controller_generator.rb +1 -1
  55. data/lib/generators/lesli/controller/templates/controller.rb.tt +12 -7
  56. data/lib/generators/lesli/model/model_generator.rb +1 -1
  57. data/lib/generators/lesli/resource/resource_generator.rb +290 -0
  58. data/lib/generators/lesli/resource/templates/controller.rb.tt +99 -0
  59. data/lib/generators/lesli/resource/templates/locale.en.yml.tt +13 -0
  60. data/lib/generators/lesli/resource/templates/migration.rb.tt +28 -0
  61. data/lib/generators/lesli/resource/templates/model.rb.tt +38 -0
  62. data/lib/generators/lesli/resource/templates/operator.rb.tt +15 -0
  63. data/lib/generators/lesli/resource/templates/service.rb.tt +52 -0
  64. data/lib/generators/lesli/resource/templates/tests/controller_test.rb.tt +14 -0
  65. data/lib/generators/lesli/resource/templates/tests/model_test.rb.tt +24 -0
  66. data/lib/generators/lesli/resource/templates/tests/operator_test.rb.tt +15 -0
  67. data/lib/generators/lesli/resource/templates/tests/service_test.rb.tt +17 -0
  68. data/lib/generators/lesli/resource/templates/views/_form.html.erb.tt +17 -0
  69. data/lib/generators/lesli/resource/templates/views/edit.html.erb.tt +4 -0
  70. data/lib/generators/lesli/resource/templates/views/index.html.erb.tt +22 -0
  71. data/lib/generators/lesli/resource/templates/views/new.html.erb.tt +4 -0
  72. data/lib/generators/lesli/resource/templates/views/show.html.erb.tt +17 -0
  73. data/lib/generators/lesli/scaffold/scaffold_generator.rb +4 -39
  74. data/lib/generators/lesli/service/service_generator.rb +1 -1
  75. data/lib/generators/lesli/service/templates/service.rb.tt +15 -7
  76. data/lib/generators/lesli/views/views_generator.rb +1 -1
  77. data/lib/generators/lesli_generator.rb +11 -0
  78. data/lib/lesli/courier.rb +66 -34
  79. data/lib/lesli/database_tasks.rb +145 -0
  80. data/lib/lesli/engine.rb +0 -4
  81. data/lib/lesli/router.rb +5 -2
  82. data/lib/lesli/version.rb +2 -2
  83. data/lib/migrate/items/activity_structure.rb +8 -8
  84. data/lib/migrate/items/attachment_structure.rb +9 -14
  85. data/lib/migrate/items/discussion_structure.rb +5 -5
  86. data/lib/migrate/items/task_structure.rb +2 -3
  87. data/lib/migrate/shared/account_structure.rb +1 -1
  88. data/lib/tasks/lesli/db.rake +16 -93
  89. data/lib/tasks/lesli/resources.rake +1 -1
  90. data/lib/tasks/lesli_tasks.rake +2 -3
  91. data/readme.md +6 -4
  92. data/test/fixtures/lesli_accounts.yml +18 -0
  93. data/test/fixtures/lesli_users.yml +23 -0
  94. metadata +39 -26
  95. data/app/assets/stylesheets/lesli/application.tailwind.css +0 -33
  96. data/app/views/lesli/partials/_application-lesli-sidebar.html.erb +0 -50
  97. data/config/brakeman.yml +0 -44
  98. data/config/initializers/devise.rb +0 -27
@@ -0,0 +1,17 @@
1
+ <%%= render(LesliView::Layout::Container.new("<%= engine_domain_name %>-<%= resource_collection_name %>-#{<%= resource_instance %>.id}")) do %>
2
+ <%%= render(LesliView::Components::Header.new(t("<%= engine_name %>.<%= resource_collection_name %>.show.title"))) %>
3
+ <% if selected_items.any? -%>
4
+ <%%= render(LesliView::Components::Tabs.new(active_tab: "<%= resource_name %>-information")) do |tabs| %>
5
+ <%% tabs.with_tab(id: "<%= resource_name %>-information", title: "Information", icon: "info") do %>
6
+ <%%= render("form") %>
7
+ <%% end %>
8
+ <% selected_items.each do |item| -%>
9
+ <%% tabs.with_tab(id: "<%= resource_name %>-<%= item %>", title: "<%= item.humanize %>", icon: "<%= { "activities" => "search_activity", "attachments" => "attach_file", "discussions" => "forum", "tasks" => "checklist" }.fetch(item) %>") do %>
10
+ <%%= render(LesliView::Items::<%= item.camelize %>.new(<%= resource_instance %>)) %>
11
+ <%% end %>
12
+ <% end -%>
13
+ <%% end %>
14
+ <% else -%>
15
+ <%%= render("form") %>
16
+ <% end -%>
17
+ <%% end %>
@@ -1,47 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rails/generators"
4
- require_relative "../base_generator"
3
+ require_relative "../resource/resource_generator"
5
4
 
6
5
  module Lesli
7
6
  module Generators
8
- # Main Lesli scaffold generator.
9
- #
10
- # This generator delegates work to the specialized generators.
11
- class ScaffoldGenerator < BaseGenerator
12
- argument :attributes, type: :array, default: [], banner: "field:type field:type"
13
-
14
- def invoke_model_generator
15
- invoke "lesli:model", [name, *attributes]
16
- end
17
-
18
- # Invokes the custom Lesli controller generator.
19
- def invoke_controller_generator
20
- invoke "lesli:controller", [name, *attributes]
21
- end
22
-
23
- # Invokes the custom Lesli service generator.
24
- def invoke_service_generator
25
- invoke "lesli:service", [name, *attributes]
26
- end
27
-
28
- def invoke_views_generator
29
- invoke "lesli:views", [name, *attributes]
30
- end
31
-
32
- def invoke_migration_generator
33
- invoke "active_record:migration", [migration_name, *attributes]
34
- end
35
-
36
- def invoke_route_generator
37
- invoke "resource_route", [resource_collection_name]
38
- end
39
-
40
- private
41
-
42
- def migration_name
43
- "create_#{engine_name}_#{resource_collection_name}"
44
- end
7
+ # Backwards-compatible name for the complete Lesli resource generator.
8
+ class ScaffoldGenerator < ResourceGenerator
9
+ source_root ResourceGenerator.source_root
45
10
  end
46
11
  end
47
12
  end
@@ -25,7 +25,7 @@ module Lesli
25
25
  # app/services/my_engine
26
26
  # app/services/store
27
27
  def service_directory
28
- File.join(ENGINE_ROOT, "app/services", engine_name)
28
+ engine_root.join("app/services", engine_name)
29
29
  end
30
30
 
31
31
  # Returns the final service file path.
@@ -9,8 +9,9 @@ module <%= engine_namespace %>
9
9
  # Build the search hash using only present values.
10
10
  params = { id: id, uid: uid }.compact
11
11
 
12
- # Only perform the lookup when at least one filter is present.
13
- super(scope.find_by(params)) if params.any?
12
+ # An empty search must not return the first record in the account.
13
+ resource = scope.find_by(params) if params.any?
14
+ super(resource)
14
15
  end
15
16
 
16
17
  def index
@@ -19,10 +20,9 @@ module <%= engine_namespace %>
19
20
 
20
21
  def create(<%= params_method_name %>)
21
22
  <%= resource_name %> = current_user.account.<%= engine_domain_name %>.<%= resource_collection_name %>.new(<%= params_method_name %>)
23
+ self.resource = <%= resource_name %>
22
24
 
23
- if <%= resource_name %>.save
24
- self.resource = <%= resource_name %>
25
- else
25
+ unless <%= resource_name %>.save
26
26
  self.error(<%= resource_name %>.errors.full_messages.to_sentence)
27
27
  end
28
28
 
@@ -34,11 +34,19 @@ module <%= engine_namespace %>
34
34
  end
35
35
 
36
36
  def update(params)
37
- self.resource.update(params)
37
+ unless resource.update(params)
38
+ error(resource.errors.full_messages.to_sentence)
39
+ end
40
+
41
+ self
38
42
  end
39
43
 
40
44
  def destroy
41
- self.resource.destroy
45
+ unless resource.destroy
46
+ error(resource.errors.full_messages.to_sentence)
47
+ end
48
+
49
+ self
42
50
  end
43
51
  end
44
52
  end
@@ -54,7 +54,7 @@ module Lesli
54
54
  # Example:
55
55
  # app/views/lesli_support/tickets
56
56
  def views_directory
57
- File.join(ENGINE_ROOT, "app/views", engine_name, resource_collection_name)
57
+ engine_root.join("app/views", engine_name, resource_collection_name)
58
58
  end
59
59
 
60
60
  # Returns only scalar-like attributes that can be rendered
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lesli/resource/resource_generator"
4
+
5
+ # Provides the concise `rails generate lesli RESOURCE` command while the
6
+ # implementation remains available as `lesli:resource`.
7
+ class LesliGenerator < Lesli::Generators::ResourceGenerator
8
+ namespace "lesli"
9
+ source_root Lesli::Generators::ResourceGenerator.source_root
10
+ desc "Generate a complete account-scoped resource inside a Lesli engine"
11
+ end
data/lib/lesli/courier.rb CHANGED
@@ -33,55 +33,87 @@ Building a better future, one line of code at a time.
33
33
  module Lesli
34
34
  class Courier
35
35
 
36
- # Store the module_name (e.g., :lesli_support as LesliSupport)
37
- def initialize(module_name, on_error=nil)
36
+ # Configure the optional engine and its error behavior.
37
+ #
38
+ # module_name: engine module name as a String or Symbol.
39
+ # fallback: value returned when the engine is unavailable or an error is handled.
40
+ # fallback_on_error: return the fallback instead of raising execution errors.
41
+ def initialize(module_name, fallback=nil, fallback_on_error: false)
38
42
  @module_name = module_name.to_s.camelize
39
- @on_error = on_error
43
+ @fallback = fallback
44
+ @fallback_on_error = fallback_on_error
40
45
  end
41
46
 
42
- # Dynamically determine the class to call (e.g., :ticket_service as TicketService)
43
- def from(service_name, *args)
44
- @service_params = args
47
+ # Select the class to instantiate (e.g., :ticket_service as TicketService),
48
+ # store its constructor arguments, and return self to keep the call chainable.
49
+ #
50
+ # service_name: class name as a String or Symbol.
51
+ # *args: positional arguments passed to the class constructor.
52
+ # **kwargs: keyword arguments passed to the class constructor.
53
+ def from(service_name, *args, **kwargs)
54
+ @service_args = args
55
+ @service_kwargs = kwargs
45
56
  @service_name = service_name.to_s.camelize
46
57
  self
47
58
  end
48
59
 
49
- # Store the method name to call on the service (e.g., :index_with_deadline)
50
- def call(method_name, *args)
51
- @method_params = args
60
+ # Select and execute a public method on the configured class instance.
61
+ #
62
+ # method_name: method name as a String or Symbol.
63
+ # *args: positional arguments passed to the method.
64
+ # **kwargs: keyword arguments passed to the method.
65
+ # Returns the value returned by the invoked method.
66
+ def call(method_name, *args, **kwargs)
67
+ @method_args = args
68
+ @method_kwargs = kwargs
52
69
  @method_name = method_name
53
- self.execute
70
+ execute
54
71
  end
55
72
 
56
- private
73
+ private
57
74
 
58
- # Execute the final call to the service, either with or without params
75
+ # The engine is always optional. Errors from an installed engine remain
76
+ # visible unless the caller explicitly enables fallback_on_error.
59
77
  def execute
78
+ # Resolve the configured engine name as a top-level Ruby module.
79
+ engine_module = resolve_constant(Object, @module_name)
80
+
81
+ # Return the configured fallback when the optional engine is not installed.
82
+ return fallback unless engine_module
83
+
84
+ # Resolve the configured class directly inside the engine module.
85
+ service_class = engine_module.const_get(@service_name, false)
86
+
87
+ # Instantiate the class with the arguments previously stored by `from`.
88
+ service = service_class.new(*@service_args, **@service_kwargs)
89
+
90
+ # Invoke the public method configured by `call` and return its result.
91
+ service.public_send(@method_name, *@method_args, **@method_kwargs)
92
+ rescue StandardError => error
93
+ # Re-raise by default so integration and implementation errors remain visible.
94
+ raise unless @fallback_on_error
95
+
96
+ # Record handled errors without interrupting the caller's execution.
97
+ Rails.error.report(
98
+ error,
99
+ handled: true,
100
+ context: {
101
+ module_name: @module_name,
102
+ service_name: @service_name,
103
+ method_name: @method_name
104
+ }
105
+ )
106
+
107
+ # Allow optional integrations to fail without breaking the calling feature.
108
+ fallback
109
+ end
60
110
 
61
- module_name = "#{@module_name}"
62
-
63
- # Look up the module and class dynamically
64
- raise unless Object.const_defined?(module_name)
65
-
66
- module_service_name = "#{@module_name}::#{@service_name}"
67
-
68
- raise unless Object.const_defined?(module_service_name)
69
-
70
- # Create a reference of the module service object
71
- module_service_class = module_service_name.constantize
72
-
73
- # Instantiate the service class with or without arguments
74
- module_service_instance = module_service_class.new(*@service_params.to_a)
75
-
76
- # Check if the method is defined on the service instance
77
- raise unless module_service_instance.respond_to?(@method_name)
111
+ attr_reader :fallback
78
112
 
79
- # Dynamically call the method on the service instance
80
- module_service_instance.send(@method_name, *@method_params)
113
+ def resolve_constant(namespace, constant_name)
114
+ return unless namespace.const_defined?(constant_name, false)
81
115
 
82
- rescue => e
83
- ## pp e add a debug message
84
- return @on_error
116
+ namespace.const_get(constant_name, false)
85
117
  end
86
118
  end
87
119
  end
@@ -0,0 +1,145 @@
1
+ =begin
2
+
3
+ Lesli
4
+
5
+ Copyright (c) 2026, Lesli Technologies, S. A.
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU General Public License as published by
9
+ the Free Software Foundation, either version 3 of the License, or
10
+ (at your option) any later version.
11
+
12
+ This program is distributed in the hope that it will be useful,
13
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
14
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
+ GNU General Public License for more details.
16
+
17
+ You should have received a copy of the GNU General Public License
18
+ along with this program. If not, see http://www.gnu.org/licenses/.
19
+
20
+ Lesli · Ruby on Rails SaaS Development Framework.
21
+
22
+ Made with ♥ by LesliTech
23
+ Building a better future, one line of code at a time.
24
+
25
+ @contact hello@lesli.tech
26
+ @website https://www.lesli.tech
27
+ @license GPLv3 http://www.gnu.org/licenses/gpl-3.0.en.html
28
+
29
+ // · ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~ ~·~
30
+ // ·
31
+ =end
32
+
33
+ module Lesli
34
+ class DatabaseTasks
35
+
36
+ # Rails calls this object when db:prepare creates a new database. Its
37
+ # intentionally empty implementation keeps preparation separate from seeds.
38
+ class SeedlessLoader
39
+ def load_seed
40
+ end
41
+ end
42
+ private_constant :SeedlessLoader
43
+
44
+ def rebuild
45
+ reset_database
46
+ seed_database
47
+ configure_database
48
+ print_status
49
+ end
50
+
51
+ def build
52
+ prepare_database
53
+ seed_database
54
+ configure_database
55
+ print_status
56
+ end
57
+
58
+ def prepare
59
+ prepare_database
60
+ configure_database
61
+ print_status
62
+ end
63
+
64
+ def seed
65
+ seed_database
66
+ configure_database
67
+ print_status
68
+ end
69
+
70
+ private
71
+
72
+ def reset_database
73
+ unless Rails.env.development? || Rails.env.test?
74
+ raise "lesli:db:rebuild can only run in development or test"
75
+ end
76
+
77
+ Termline.m("Rebuild the Lesli database from migrations (development and test only)")
78
+
79
+ Rake::Task["db:migrate:reset"].invoke
80
+ Termline.info("Databases rebuilt from the available migrations")
81
+ end
82
+
83
+ def prepare_database
84
+ Termline.info("Prepare the Lesli database")
85
+
86
+ database_tasks = ActiveRecord::Tasks::DatabaseTasks
87
+ original_seed_loader = database_tasks.seed_loader
88
+
89
+ database_tasks.seed_loader = SeedlessLoader.new
90
+ Rake::Task["db:prepare"].invoke
91
+ ensure
92
+ database_tasks.seed_loader = original_seed_loader if database_tasks
93
+ end
94
+
95
+ def seed_database
96
+ Termline.info("Seed the Lesli database")
97
+
98
+ LesliSystem.engines.each_key do |engine|
99
+ next if engine == "Root"
100
+
101
+ engine.constantize::Engine.load_seed
102
+ end
103
+
104
+ Termline.info("Loading seeds for: Main app")
105
+ Rake::Task["db:seed"].invoke
106
+ Termline.br(2)
107
+ end
108
+
109
+ def configure_database
110
+ Termline.info("Configure the Lesli database")
111
+
112
+ build_resources
113
+ initialize_accounts
114
+ synchronize_privileges
115
+ synchronize_translations
116
+ end
117
+
118
+ def build_resources
119
+ Rake::Task["lesli:resources:build"].invoke
120
+ end
121
+
122
+ def initialize_accounts
123
+ Lesli::Account.find_each do |account|
124
+ operator = Lesli::AccountOperator.new(account: account)
125
+ operator.initialize_roles!
126
+ operator.initialize_engines!
127
+ end
128
+ end
129
+
130
+ def synchronize_privileges
131
+ Rake::Task["lesli_shield:privileges"].invoke if defined?(::LesliShield)
132
+ end
133
+
134
+ def synchronize_translations
135
+ return unless defined?(::LesliBabel)
136
+
137
+ Rake::Task["lesli_babel:scan"].invoke
138
+ Rake::Task["lesli_babel:import"].invoke(true)
139
+ end
140
+
141
+ def print_status
142
+ Rake::Task["lesli:status"].invoke
143
+ end
144
+ end
145
+ end
data/lib/lesli/engine.rb CHANGED
@@ -38,10 +38,6 @@ require "kaminari"
38
38
  require "termline"
39
39
  require "acts_as_paranoid"
40
40
 
41
- # The hole Lesli ecosystem depends on current_user, so we
42
- # include the dependency in the core
43
- require "devise"
44
-
45
41
  require "lesli_date"
46
42
  require "lesli_view"
47
43
  require "lesli_assets"
data/lib/lesli/router.rb CHANGED
@@ -74,10 +74,13 @@ module Lesli
74
74
  router.namespace :items do
75
75
 
76
76
  # Load item tasks
77
- router.resources :tasks, only: %i[index update create]
77
+ router.resources :tasks, only: %i[update create]
78
78
 
79
79
  # Load item discussions
80
- router.resources :discussions, only: %i[index update create]
80
+ router.resources :discussions, only: :create
81
+
82
+ # Load attachments
83
+ router.resources :attachments, only: %i[index show create destroy]
81
84
  end
82
85
 
83
86
  # Optional: health check inside engine scope (pick a consistent path)
data/lib/lesli/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Lesli
2
- VERSION = "5.1.12"
3
- BUILD = "1791607001"
2
+ VERSION = "5.1.14"
3
+ BUILD = "1794793515"
4
4
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Lesli
4
4
 
5
- Copyright (c) 2025, Lesli Technologies, S. A.
5
+ Copyright (c) 2026, Lesli Technologies, S. A.
6
6
 
7
7
  This program is free software: you can redistribute it and/or modify
8
8
  it under the terms of the GNU General Public License as published by
@@ -35,7 +35,7 @@ module MigrationHelpers
35
35
  module ActivityStructure
36
36
  def create_table_lesli_item_activities_10(engine)
37
37
 
38
- table_name, foreign_key = table_name_for_items(engine, :activities)
38
+ table_name, = table_name_for_items(engine, :activities)
39
39
 
40
40
  create_table table_name do |t|
41
41
 
@@ -43,13 +43,13 @@ module MigrationHelpers
43
43
  t.string :description
44
44
 
45
45
  # Tipo principal del registro
46
- t.string :activity_type, null: false, default: :activity
46
+ t.string :activity_type, null: false, default: "activity"
47
47
 
48
48
  # Subtipo para actividades
49
- t.string :activity_code
49
+ t.string :activity_code, null: false
50
50
 
51
51
  # Metadatos opcionales (JSON)
52
- t.json :metadata, default: {}
52
+ t.json :metadata, null: false, default: {}
53
53
 
54
54
  # Polymorphic target
55
55
  t.string :subject_type, null: false
@@ -59,9 +59,9 @@ module MigrationHelpers
59
59
  t.datetime :deleted_at, index: true
60
60
  end
61
61
 
62
- add_reference(table_name, :user, foreign_key: { to_table: :lesli_users })
63
- add_reference(table_name, :account, foreign_key: { to_table: "#{engine}_accounts".to_sym })
64
- add_index(table_name, [:account_id, :subject_type, :subject_id], name: "#{table_name}_activities_type_id")
62
+ add_reference(table_name, :user, null: false, foreign_key: { to_table: :lesli_users })
63
+ add_reference(table_name, :account, null: false, foreign_key: { to_table: "#{engine}_accounts".to_sym })
64
+ add_index(table_name, [:subject_type, :subject_id, :deleted_at, :created_at, :id], name: "#{table_name}_timeline")
65
65
  end
66
66
  end
67
67
  end
@@ -2,7 +2,7 @@
2
2
 
3
3
  Lesli
4
4
 
5
- Copyright (c) 2025, Lesli Technologies, S. A.
5
+ Copyright (c) 2026, Lesli Technologies, S. A.
6
6
 
7
7
  This program is free software: you can redistribute it and/or modify
8
8
  it under the terms of the GNU General Public License as published by
@@ -33,29 +33,24 @@ Building a better future, one line of code at a time.
33
33
  module MigrationHelpers
34
34
  module Items
35
35
  module AttachmentStructure
36
- def create_table_lesli_item_attachments_10(resources)
36
+ def create_table_lesli_item_attachments_10(engine)
37
37
 
38
- table_name, foreign_key = table_name_for_items(resources, :attachments)
38
+ table_name, = table_name_for_items(engine, :attachments)
39
39
 
40
40
  create_table table_name do |t|
41
- t.string :name
41
+ t.string :label
42
42
  t.string :category
43
- t.decimal :size_mb
44
43
 
45
- t.string :attachment
46
- t.string :attachment_remote # like S3
47
- t.string :attachment_public
48
-
49
- t.boolean :public
50
- t.string :public_url
51
- t.datetime :public_url_expiration_at
44
+ t.string :attachable_type, null: false
45
+ t.bigint :attachable_id, null: false
52
46
 
53
47
  t.datetime :deleted_at, index: true
54
48
  t.timestamps
55
49
  end
56
50
 
57
- add_reference(table_name, :user, foreign_key: { to_table: :lesli_users })
58
- add_reference(table_name, foreign_key, foreign_key: { to_table: resources })
51
+ add_reference(table_name, :user, null: false, foreign_key: { to_table: :lesli_users })
52
+ add_reference(table_name, :account, null: false, foreign_key: { to_table: "#{engine}_accounts".to_sym })
53
+ add_index(table_name, [:account_id, :attachable_type, :attachable_id], name: "#{table_name}_attachable_type_id".to_sym)
59
54
  end
60
55
  end
61
56
  end
@@ -35,21 +35,21 @@ module MigrationHelpers
35
35
  module DiscussionStructure
36
36
  def create_table_lesli_item_discussions_10(engine)
37
37
 
38
- table_name, foreign_key = table_name_for_items(engine, :discussions)
38
+ table_name, = table_name_for_items(engine, :discussions)
39
39
 
40
40
  create_table table_name do |t|
41
- t.text :message
41
+ t.text :message, null: false
42
42
 
43
43
  # Polymorphic target
44
44
  t.string :discussable_type, null: false
45
45
  t.bigint :discussable_id, null: false
46
46
 
47
47
  t.timestamps
48
- t.datetime :deleted_at, index: true
49
48
  end
50
49
 
51
- add_reference(table_name, :user, foreign_key: { to_table: :lesli_users })
52
- add_reference(table_name, :account, foreign_key: { to_table: "#{engine}_accounts".to_sym })
50
+ add_reference(table_name, :user, null: false, foreign_key: { to_table: :lesli_users })
51
+ add_reference(table_name, :account, null: false, foreign_key: { to_table: "#{engine}_accounts".to_sym })
52
+ add_index(table_name, [:account_id, :discussable_type, :discussable_id], name: "#{table_name}_discussable_type_id".to_sym)
53
53
  end
54
54
  end
55
55
  end
@@ -46,11 +46,10 @@ module MigrationHelpers
46
46
  t.bigint :taskable_id, null: false
47
47
 
48
48
  t.timestamps
49
- t.datetime :deleted_at, index: true
50
49
  end
51
50
 
52
- add_reference(table_name, :user, foreign_key: { to_table: :lesli_users })
53
- add_reference(table_name, :account, foreign_key: { to_table: "#{engine}_accounts".to_sym })
51
+ add_reference(table_name, :user, null: false, foreign_key: { to_table: :lesli_users })
52
+ add_reference(table_name, :account, null: false, foreign_key: { to_table: "#{engine}_accounts".to_sym })
54
53
  add_index(table_name, [:account_id, :taskable_type, :taskable_id], name: "#{table_name}_taskable_type_id".to_sym)
55
54
  end
56
55
  end
@@ -14,7 +14,7 @@ module MigrationHelpers
14
14
  t.timestamps
15
15
  end
16
16
 
17
- add_reference(table_name, :account, null: false, foreign_key: { to_table: :lesli_accounts }, index: true)
17
+ add_reference(table_name, :account, null: false, index: { unique: true }, foreign_key: { to_table: :lesli_accounts })
18
18
  end
19
19
  end
20
20
  end