Module: Nearline::Models

Defined in:
lib/nearline/log.rb,
lib/nearline/block.rb,
lib/nearline/schema.rb,
lib/nearline/system.rb,
lib/nearline/manifest.rb,
lib/nearline/file_content.rb,
lib/nearline/archived_file.rb,
lib/nearline/file_sequencer.rb,
lib/nearline/file_information.rb

Defined Under Namespace

Classes: ArchivedFile, Block, FileContent, FileFinder, FileInformation, FileSequencer, Log, Manifest, Sequence, System

Class Method Summary collapse

Class Method Details

.destroy_schemaObject



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/nearline/schema.rb', line 6

def destroy_schema
  ActiveRecord::Schema.define do
    drop_table :blocks
    drop_table :file_contents
    drop_table :sequences
    drop_table :archived_files
    drop_table :manifests
    drop_table :archived_files_manifests
    drop_table :logs
    drop_table :systems
    drop_table :nearline_version
  end
end

.empty_schemaObject



20
21
22
# File 'lib/nearline/schema.rb', line 20

def empty_schema
  Nearline::Models::System.destroy_all
end

.generate_schemaObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/nearline/schema.rb', line 24

def generate_schema
  ActiveRecord::Schema.define do

    create_table :blocks do |t|
      t.column :fingerprint, :string, :length => 40, :null => false
      t.column :bulk_content, :text
      t.column :is_compressed, :boolean, :default => false
    end
    
    add_index :blocks, [:fingerprint], :unique => true

    create_table :file_contents do |t|
      t.column :fingerprint, :string, :length => 40
      t.column :file_size, :string, :default => 0
      t.column :verified_at, :datetime
    end

    create_table :sequences do |t|
      t.column :sequence, :integer, :null => false
      t.column :block_id, :integer, :null => false
      t.column :file_content_id, :integer, :null => false
    end
    
    create_table :systems do |t|
      t.column :name, :string, :null => false
    end
    
    add_index :systems, [:name], :unique => true

    create_table :archived_files do |t|
      t.column :system_id, :integer, :null => false
      t.column :path, :text, :null => false
      t.column :path_hash, :string, :null => false, :length => 40
      t.column :file_content_id, :integer
      t.column :uid, :integer, :default => -1
      t.column :gid, :integer, :default => -1
      t.column :mtime, :integer, :default => 0
      t.column :mode, :integer, :default => 33206  # "chmod 100666"
      t.column :ftype, :string, :null => false
      t.column :ftype_data, :text
    end
    
    add_index :archived_files, [:path_hash], :unique => true
                    
    # Manifests are the reference to a collection of archived files
    create_table :manifests do |t|
      t.column :system_id, :integer
      t.column :created_at, :datetime
      t.column :completed_at, :datetime
    end
    
    # Joins archived files across manifests so file references may be recycled
    create_table :archived_files_manifests, :id => false do |t|
      t.column :archived_file_id, :integer
      t.column :manifest_id, :integer
    end
    
    # Keeps a record of problems during backup related to a manifest
    create_table :logs do |t|
      t.column :manifest_id, :integer, :null => false
      t.column :message, :text
      t.column :created_at, :datetime
    end
    
    create_table :nearline_version, :id => false do |t|
      t.column :version, :string
    end
    
    execute "insert into nearline_version (version) values ('#{Nearline::DB_VERSION}')"        
  end
end