diff --git a/app/models/bacula_file.rb b/app/models/bacula_file.rb index 6eceb33..abbab57 100644 --- a/app/models/bacula_file.rb +++ b/app/models/bacula_file.rb @@ -1,13 +1,19 @@ class BaculaFile < ActiveRecord::Base self.table_name = :File self.primary_key = :FileId alias_attribute :file_index, :FileIndex alias_attribute :job_id, :JobId alias_attribute :path_id, :PathId alias_attribute :filename_id, :FilenameId alias_attribute :delta_seq, :DeltaSeq alias_attribute :mark_id, :MarkId alias_attribute :l_stat, :LStat alias_attribute :md5, :MD5 + + belongs_to :path, foreign_key: :PathId + belongs_to :filename, foreign_key: :FilenameId + belongs_to :job, foreign_key: :JobId + + has_many :base_files, foreign_key: :FileId end diff --git a/app/models/base_file.rb b/app/models/base_file.rb index 0a8f953..a7eb94a 100644 --- a/app/models/base_file.rb +++ b/app/models/base_file.rb @@ -1,13 +1,17 @@ # The BaseFiles table contains all the File references for a particular JobId that point # to a Base file - i.e. they were previously saved and hence were not saved in the current # JobId but in BaseJobId under FileId. class BaseFile < ActiveRecord::Base self.table_name = :BaseFiles self.primary_key = :BaseId alias_attribute :id, :BaseId alias_attribute :base_job_id, :BaseJobId alias_attribute :job_id, :JobId alias_attribute :file_id, :FileId alias_attribute :file_index, :FileIndex + + belongs_to :base_job, foreign_key: :BaseJobId, class_name: :Job + belongs_to :job, foreign_key: :JobId + belongs_to :bacula_file, foreign_key: :FileId end diff --git a/app/models/client.rb b/app/models/client.rb index d68836c..44febc2 100644 --- a/app/models/client.rb +++ b/app/models/client.rb @@ -1,10 +1,12 @@ class Client < ActiveRecord::Base self.table_name = :Client self.primary_key = :ClientId alias_attribute :name, :Name alias_attribute :uname, :Uname alias_attribute :auto_prune, :AutoPrune alias_attribute :file_retention, :FileRetention alias_attribute :job_retention, :JobRetention + + has_many :jobs, foreign_key: :ClientId end diff --git a/app/models/device.rb b/app/models/device.rb index 71c0c37..64c342e 100644 --- a/app/models/device.rb +++ b/app/models/device.rb @@ -1,20 +1,22 @@ class Device < ActiveRecord::Base self.table_name = :Device self.primary_key = :DeviceId alias_attribute :device_id, :DeviceId alias_attribute :name, :Name alias_attribute :media_type_id, :MediaTypeId alias_attribute :storage_id, :StorageId alias_attribute :dev_mounts, :DevMounts alias_attribute :dev_read_bytes, :DevReadBytes alias_attribute :dev_write_bytes, :DevWriteBytes alias_attribute :dev_read_bytes_since_cleaning, :DevReadBytesSinceCleaning alias_attribute :dev_write_bytes_since_cleaning, :DevWriteBytesSinceCleaning alias_attribute :dev_read_time, :DevReadTime alias_attribute :dev_write_time, :DevWriteTime alias_attribute :dev_read_time_since_cleaning, :DevReadTimeSinceCleaning alias_attribute :dev_write_time_since_cleaning, :DevWriteTimeSinceCleaning alias_attribute :cleaning_date, :CleaningDate alias_attribute :cleaning_period, :CleaningPeriod + + has_many :media, foreign_key: :DeviceId end diff --git a/app/models/file_set.rb b/app/models/file_set.rb index d3ff48e..9896de0 100644 --- a/app/models/file_set.rb +++ b/app/models/file_set.rb @@ -1,9 +1,11 @@ class FileSet < ActiveRecord::Base self.table_name = :FileSet self.primary_key = :FileSetId alias_attribute :file_set_id, :FileSetId alias_attribute :file_set, :FileSet alias_attribute :md5, :MD5 alias_attribute :create_time, :CreateTime + + has_many :jobs, foreign_key: :FileSetId end diff --git a/app/models/filename.rb b/app/models/filename.rb index 1abec4d..a612570 100644 --- a/app/models/filename.rb +++ b/app/models/filename.rb @@ -1,7 +1,9 @@ class Filename < ActiveRecord::Base self.table_name = :Filename self.primary_key = :FilenameId alias_attribute :filename_id, :FilenameId alias_attribute :name, :Name + + has_many :bacula_files, foreign_key: :FilenameId end diff --git a/app/models/job.rb b/app/models/job.rb index b34a06d..a2d904a 100644 --- a/app/models/job.rb +++ b/app/models/job.rb @@ -1,32 +1,41 @@ class Job < ActiveRecord::Base self.table_name = :Job self.primary_key = :JobId alias_attribute :job_id, :JobId alias_attribute :job, :Job alias_attribute :name, :Name alias_attribute :type, :Type alias_attribute :level, :Level alias_attribute :client_id, :ClientId alias_attribute :job_status, :JobStatus alias_attribute :sched_time, :SchedTime alias_attribute :start_time, :StartTime alias_attribute :end_time, :EndTime alias_attribute :real_end_time, :RealEndTime alias_attribute :job_t_date, :JobTDate alias_attribute :vol_session_id, :VolSessionId alias_attribute :vol_session_time, :VolSessionTime alias_attribute :job_files, :JobFiles alias_attribute :job_bytes, :JobBytes alias_attribute :read_bytes, :ReadBytes alias_attribute :job_errors, :JobErrors alias_attribute :job_missing_files, :JobMissingFiles alias_attribute :pool_id, :PoolId alias_attribute :file_set_id, :FileSetId alias_attribute :prior_job_id, :PriorJobId alias_attribute :purged_files, :PurgedFiles alias_attribute :has_base, :HasBase alias_attribute :has_cache, :HasCache alias_attribute :reviewed, :Reviewed alias_attribute :comment, :Comment + + belongs_to :pool, foreign_key: :PoolId + belongs_to :file_set, foreign_key: :FileSetId + belongs_to :client, foreign_key: :ClientId + + has_many :bacula_files, foreign_key: :JobId + has_many :base_files, foreign_key: :BaseJobId + has_many :job_media, foreign_key: :JobId + has_many :logs, foreign_key: :JobId end diff --git a/app/models/job_histo.rb b/app/models/job_histo.rb index 8f89229..a74a775 100644 --- a/app/models/job_histo.rb +++ b/app/models/job_histo.rb @@ -1,31 +1,35 @@ class JobHisto < ActiveRecord::Base self.table_name = :JobHisto alias_attribute :job_id, :JobId alias_attribute :job, :Job alias_attribute :name, :Name alias_attribute :type, :Type alias_attribute :level, :Level alias_attribute :client_id, :ClientId alias_attribute :job_status, :JobStatus alias_attribute :sched_time, :SchedTime alias_attribute :start_time, :StartTime alias_attribute :end_time, :EndTime alias_attribute :real_end_time, :RealEndTime alias_attribute :job_t_date, :JobTDate alias_attribute :vol_session_id, :VolSessionId alias_attribute :vol_session_time, :VolSessionTime alias_attribute :job_files, :JobFiles alias_attribute :job_bytes, :JobBytes alias_attribute :read_bytes, :ReadBytes alias_attribute :job_errors, :JobErrors alias_attribute :job_missing_files, :JobMissingFiles alias_attribute :pool_id, :PoolId alias_attribute :file_set_id, :FileSetId alias_attribute :prior_job_id, :PriorJobId alias_attribute :purged_files, :PurgedFiles alias_attribute :has_base, :HasBase alias_attribute :has_cache, :HasCache alias_attribute :reviewed, :Reviewed alias_attribute :comment, :Comment + + belongs_to :client, foreign_key: :ClientId + belongs_to :pool, foreign_key: :PoolId + belongs_to :file_set, foreign_key: :FileSetId end diff --git a/app/models/job_media.rb b/app/models/job_media.rb index ac4643e..8f07497 100644 --- a/app/models/job_media.rb +++ b/app/models/job_media.rb @@ -1,15 +1,18 @@ class JobMedia < ActiveRecord::Base self.table_name = :JobMedia self.primary_key = :JobMediaId alias_attribute :job_media_id, :JobMediaId alias_attribute :job_id, :JobId alias_attribute :media_id, :MediaId alias_attribute :first_index, :FirstIndex alias_attribute :last_index, :LastIndex alias_attribute :start_file, :StartFile alias_attribute :end_file, :EndFile alias_attribute :start_block, :StartBlock alias_attribute :end_block, :EndBlock alias_attribute :vol_index, :VolIndex + + belongs_to :Job, foreign_key: :JobId + belongs_to :Media, foreign_key: :MediaId end diff --git a/app/models/location.rb b/app/models/location.rb index 7faf1b3..4411af5 100644 --- a/app/models/location.rb +++ b/app/models/location.rb @@ -1,9 +1,12 @@ class Location < ActiveRecord::Base self.table_name = :Location self.primary_key = :LocationId alias_attribute :location_id, :LocationId alias_attribute :location, :Location alias_attribute :cost, :Cost alias_attribute :enabled, :Enabled + + has_many :media, foreign_key: :LocationId + has_many :location_logs, foreign_key: :LocationId end diff --git a/app/models/location_log.rb b/app/models/location_log.rb index fc5e784..c82ddd2 100644 --- a/app/models/location_log.rb +++ b/app/models/location_log.rb @@ -1,12 +1,15 @@ class LocationLog < ActiveRecord::Base self.table_name = :LocationLog self.primary_key = :LocLogId alias_attribute :loc_log_id, :LocLogId alias_attribute :date, :Date alias_attribute :comment, :Comment alias_attribute :media_id, :MediaId alias_attribute :location_id, :LocationId alias_attribute :new_vol_status, :NewVolStatus alias_attribute :new_enabled, :NewEnabled + + belongs_to :media, foreign_key: :MediaId + belongs_to :location, foreign_key: :LocationId end diff --git a/app/models/log.rb b/app/models/log.rb index 2c10c39..7eba933 100644 --- a/app/models/log.rb +++ b/app/models/log.rb @@ -1,9 +1,11 @@ class Log < ActiveRecord::Base self.table_name = :Log self.primary_key = :LogId alias_attribute :log_id, :LogId alias_attribute :job_id, :JobId alias_attribute :time, :Time alias_attribute :log_text, :LogText + + belongs_to :job, foreign_key: :JobId end diff --git a/app/models/media.rb b/app/models/media.rb index a701d5c..339d4b7 100644 --- a/app/models/media.rb +++ b/app/models/media.rb @@ -1,47 +1,55 @@ class Media < ActiveRecord::Base self.table_name = :Media self.primary_key = :MediaId alias_attribute :media_id, :MediaId alias_attribute :volume_name, :VolumeName alias_attribute :slot, :Slot alias_attribute :pool_id, :PoolId alias_attribute :media_type, :MediaType alias_attribute :media_type_id, :MediaTypeId alias_attribute :label_type, :LabelType alias_attribute :first_written, :FirstWritten alias_attribute :last_written, :LastWritten alias_attribute :label_date, :LabelDate alias_attribute :vol_jobs, :VolJobs alias_attribute :vol_files, :VolFiles alias_attribute :vol_blocks, :VolBlocks alias_attribute :vol_mounts, :VolMounts alias_attribute :vol_bytes, :VolBytes alias_attribute :vol_parts, :VolParts alias_attribute :vol_errors, :VolErrors alias_attribute :vol_writes, :VolWrites alias_attribute :vol_capacity_bytes, :VolCapacityBytes alias_attribute :vol_status, :VolStatus alias_attribute :enabled, :Enabled alias_attribute :recycle, :Recycle alias_attribute :action_on_purge, :ActionOnPurge alias_attribute :vol_retention, :VolRetention alias_attribute :vol_use_duration, :VolUseDuration alias_attribute :max_vol_jobs, :MaxVolJobs alias_attribute :max_vol_files, :MaxVolFiles alias_attribute :max_vol_bytes, :MaxVolBytes alias_attribute :in_changer, :InChanger alias_attribute :storage_id, :StorageId alias_attribute :device_id, :DeviceId alias_attribute :media_addressing, :MediaAddressing alias_attribute :vol_read_time, :VolReadTime alias_attribute :vol_write_time, :VolWriteTime alias_attribute :end_file, :EndFile alias_attribute :end_block, :EndBlock alias_attribute :location_id, :LocationId alias_attribute :recycle_count, :RecycleCount alias_attribute :initial_write, :InitialWrite alias_attribute :scratch_pool_id, :ScratchPoolId alias_attribute :recycle_pool_id, :RecyclePoolId alias_attribute :comment, :Comment + + belongs_to :pool, foreign_key: :PoolId + belongs_to :storage, foreign_key: :StorageId + belongs_to :device, foreign_key: :DeviceId + belongs_to :location, foreign_key: :LocationId + + has_many :job_media, foreign_key: :MediaId + has_many :location_logs, foreign_key: :MediaId end diff --git a/app/models/path.rb b/app/models/path.rb index d4e01fd..847b32d 100644 --- a/app/models/path.rb +++ b/app/models/path.rb @@ -1,7 +1,9 @@ class Path < ActiveRecord::Base self.table_name = :Path self.primary_key = :PathId alias_attribute :path_id, :PathId alias_attribute :path, :Path + + has_many :bacula_files, foreign_key: :PathId end diff --git a/app/models/pool.rb b/app/models/pool.rb index de66a54..295a7c3 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -1,30 +1,33 @@ class Pool < ActiveRecord::Base self.table_name = :Pool self.primary_key = :PoolId alias_attribute :pool_id, :PoolId alias_attribute :name, :Name alias_attribute :num_vols, :NumVols alias_attribute :max_vols, :MaxVols alias_attribute :use_once, :UseOnce alias_attribute :use_catalog, :UseCatalog alias_attribute :accept_any_volume, :AcceptAnyVolume alias_attribute :vol_retention, :VolRetention alias_attribute :vol_use_duration, :VolUseDuration alias_attribute :max_vol_jobs, :MaxVolJobs alias_attribute :max_vol_files, :MaxVolFiles alias_attribute :max_vol_bytes, :MaxVolBytes alias_attribute :auto_prune, :AutoPrune alias_attribute :recycle, :Recycle alias_attribute :action_on_purge, :ActionOnPurge alias_attribute :pool_type, :PoolType alias_attribute :label_type, :LabelType alias_attribute :label_format, :LabelFormat alias_attribute :enabled, :Enabled alias_attribute :scratch_pool_id, :ScratchPoolId alias_attribute :recycle_pool_id, :RecyclePoolId alias_attribute :next_pool_id, :NextPoolId alias_attribute :migration_high_bytes, :MigrationHighBytes alias_attribute :migration_low_bytes, :MigrationLowBytes alias_attribute :migration_time, :MigrationTime + + has_many :jobs, foreign_key: :PoolId + has_many :media, foreign_key: :PoolId end diff --git a/app/models/storage.rb b/app/models/storage.rb index 7aad3e3..bb6249e 100644 --- a/app/models/storage.rb +++ b/app/models/storage.rb @@ -1,8 +1,10 @@ class Storage < ActiveRecord::Base self.table_name = :Storage self.primary_key = :StorageId alias_attribute :storage_id, :StorageId alias_attribute :name, :Name alias_attribute :auto_changer, :AutoChanger + + has_many :media, foreign_key: :StorageId end