diff options
Diffstat (limited to 'app/models/referential.rb')
| -rw-r--r-- | app/models/referential.rb | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/app/models/referential.rb b/app/models/referential.rb index 933bc78e3..0c6e71d47 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -26,6 +26,7 @@ class Referential < ApplicationModel has_one :user has_many :api_keys, class_name: 'Api::V1::ApiKey', dependent: :destroy + has_many :import_resources, class_name: 'Import::Resource', dependent: :destroy belongs_to :organisation validates_presence_of :organisation @@ -59,7 +60,6 @@ class Referential < ApplicationModel belongs_to :referential_suite - scope :pending, -> { where(ready: false, failed_at: nil, archived_at: nil) } scope :active, -> { where(ready: true, failed_at: nil, archived_at: nil) } scope :failed, -> { where.not(failed_at: nil) } @@ -271,7 +271,8 @@ class Referential < ApplicationModel stop_area_referential: from.stop_area_referential, created_from: from, objectid_format: from.objectid_format, - metadatas: from.metadatas.map { |m| ReferentialMetadata.new_from(m, organisation) } + metadatas: from.metadatas.map { |m| ReferentialMetadata.new_from(m, organisation) }, + ready: false ) end @@ -322,6 +323,7 @@ class Referential < ApplicationModel before_create :create_schema after_create :clone_schema, if: :created_from + after_create :active!, unless: :created_from before_destroy :destroy_schema before_destroy :destroy_jobs @@ -397,7 +399,7 @@ class Referential < ApplicationModel query = "select distinct(public.referential_metadata.referential_id) FROM public.referential_metadata, unnest(line_ids) line, LATERAL unnest(periodes) period WHERE public.referential_metadata.referential_id - IN (SELECT public.referentials.id FROM public.referentials WHERE referentials.workbench_id = #{workbench_id} and referentials.archived_at is null and referentials.referential_suite_id is null #{not_myself}) + IN (SELECT public.referentials.id FROM public.referentials WHERE referentials.workbench_id = #{workbench_id} and referentials.archived_at is null and referentials.referential_suite_id is null #{not_myself} AND referentials.failed_at IS NULL) AND line in (#{line_ids.join(',')}) and (#{periods_query});" self.class.connection.select_values(query).map(&:to_i) @@ -471,6 +473,7 @@ class Referential < ApplicationModel end def destroy_schema + return unless ActiveRecord::Base.connection.schema_names.include?(slug) Apartment::Tenant.drop slug end |
