Skip to content
  •  
  •  
  •  
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ dump/*
!log/.keep
!dump/.keep
*.gem
.byebug_history
.byebug_history
*.code-workspace
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# README

*travis-backup-for-v3* is an application that helps with housekeeping and backup for Travis CI database v3.0. It removes requests and builds with their dependencies, as long as they are older than given threshold says.
*travis-backup-for-v3* is an application that helps with housekeeping and backup for Travis CI database v3.0. By default it removes requests and builds with their dependencies, as long as they are older than given threshold says (and backups them in files, if this option is active). It can also be used to remove specified users, organizations or repositories with their dependencies.

### Installation and run

Expand Down Expand Up @@ -55,6 +55,8 @@ backup.run(repo_id: 1)

#### Special modes

Using `--user_id`, `--org_id` or `--repo_id` flag without setting `--threshold` results in removing the specified user/organization/repository with all its dependencies. It can be combined with `--backup` flag in order to save removed data in files.

Using `--dry_run` flag you can check which data would be removed by gem, but without removing them actually. Instead of that reports will be printed on standard output. This flag can be also combined with special modes.

### Configuration options
Expand Down
1 change: 0 additions & 1 deletion db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET client_min_messages = warning;
SET row_security = off;

--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
Expand Down
4 changes: 2 additions & 2 deletions lib/backup/save_nullified_rels_to_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def save_nullified_rels_to_file(rels_hash)
@file_index = 1

rels_hash.each do |name, rels|
rels&.compact&.each_slice(@config.limit.to_i) do |rels_batch|
rels&.compact&.sort{|a, b| a.to_s <=> b.to_s}&.each_slice(@config.limit.to_i) do |rels_batch|
save_rels_batch_to_file(name, rels_batch)
end
end
Expand All @@ -18,7 +18,7 @@ def save_rels_batch_to_file(name, rels_batch)

export = {}
export[:table_name] = model.table_name
export[:nullified_relationships] = rels_batch.sort{|a, b| a.to_s <=> b.to_s}
export[:nullified_relationships]

content = JSON.pretty_generate(export)
file_name = "nullified_relationships/build_#{@file_index}.json"
Expand Down
9 changes: 6 additions & 3 deletions lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,8 @@ def set_values(args)
def check_values
if !@move_logs && !@remove_orphans && !@threshold && !@user_id && !@org_id && !@repo_id && !@load_from_files
message = abort_message("Please provide the threshold argument. Data younger than it will be omitted. " +
"Threshold defines number of months from now.")
"Threshold defines number of months from now. Alternatively you can define user_id, org_id or repo_id " +
"to remove whole user, organization or repository with all dependencies.")
abort message
end

Expand All @@ -151,9 +152,11 @@ def check_values

def abort_message(intro)
"\n#{intro}\n\nExample usage:\n"+
"\n $ bin/travis_backup 'postgres://my_database_url' --threshold 6\n" +
"\n $ bin/travis_backup 'postgres://my_database_url' --threshold 6" +
"\n $ bin/travis_backup 'postgres://my_database_url' --user_id 1\n" +
"\nor using in code:\n" +
"\n Backup.new(database_url: 'postgres://my_database_url', threshold: 6)\n" +
"\n Backup.new(database_url: 'postgres://my_database_url', threshold: 6)" +
"\n Backup.new(database_url: 'postgres://my_database_url', user_id: 1)\n" +
"\nYou can also set it using environment variables or configuration files.\n"
end

Expand Down
9 changes: 0 additions & 9 deletions lib/models/deleted_build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@ class DeletedBuild < Model
belongs_to :build_config, foreign_key: :config_id, class_name: 'BuildConfig'
self.primary_key = 'id'

# has_many :jobs, -> { order('id') }, as: :source, dependent: :destroy
# has_many :repos_for_that_this_build_is_current, foreign_key: :current_build_id, dependent: :destroy, class_name: 'Repository'
# has_many :repos_for_that_this_build_is_last, foreign_key: :last_build_id, class_name: 'Repository'
# has_many :tags_for_that_this_build_is_last, foreign_key: :last_build_id, class_name: 'Tag'
# has_many :branches_for_that_this_build_is_last, foreign_key: :last_build_id, class_name: 'Branch'
# has_many :stages

# has_many :deleted_jobs, -> { order('id') }, as: :source, dependent: :destroy
# has_many :deleted_tags_for_that_this_build_is_last, foreign_key: :last_build_id, class_name: 'DeletedTag'
# has_many :deleted_stages

# def self.default_dependencies_symbols_to_nullify
# [
Expand Down
2 changes: 0 additions & 2 deletions lib/models/deleted_build_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
class DeletedBuildConfig < Model
belongs_to :repository
self.primary_key = 'id'
# has_many :builds, foreign_key: :config_id, class_name: 'Build'
# has_many :deleted_builds, foreign_key: :config_id, class_name: 'DeletedBuild'
end
6 changes: 0 additions & 6 deletions lib/models/deleted_commit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,5 @@ class DeletedCommit < Model
belongs_to :repository
belongs_to :tag
self.primary_key = 'id'
# has_many :builds
# has_many :jobs
# has_many :requests

# has_many :deleted_builds
# has_many :deleted_jobs
# has_many :deleted_requests
end
2 changes: 0 additions & 2 deletions lib/models/deleted_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,4 @@ class DeletedJob < Model
belongs_to :stage
belongs_to :job_config, foreign_key: :config_id, class_name: 'JobConfig'
self.primary_key = 'id'
# has_many :queueable_jobs
# has_many :job_versions
end
2 changes: 0 additions & 2 deletions lib/models/deleted_job_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
class DeletedJobConfig < Model
belongs_to :repository
self.primary_key = 'id'
# has_many :jobs, foreign_key: :config_id, class_name: 'Job'
# has_many :deleted_jobs, foreign_key: :config_id, class_name: 'DeletedJob'
end
4 changes: 0 additions & 4 deletions lib/models/deleted_pull_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@
class DeletedPullRequest < Model
belongs_to :repository
self.primary_key = 'id'
# has_many :requests
# has_many :builds
# has_many :deleted_requests
# has_many :deleted_builds
end
10 changes: 0 additions & 10 deletions lib/models/deleted_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,4 @@ class DeletedRequest < Model
belongs_to :request_yaml_configs
belongs_to :request_configs
self.primary_key = 'id'
# has_many :abuses
# has_many :messages, as: :subject
# has_many :jobs, as: :source
# has_many :builds
# has_many :request_payloads
# has_many :request_raw_configurations
# has_many :deleted_jobs, as: :source
# has_many :deleted_builds
# has_many :deleted_request_payloads
# has_many :deleted_request_raw_configurations
end
2 changes: 0 additions & 2 deletions lib/models/deleted_request_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
class DeletedRequestConfig < Model
belongs_to :repository
self.primary_key = 'id'
# has_many :requests, foreign_key: :config_id, class_name: 'Request'
# has_many :deleted_requests, foreign_key: :config_id, class_name: 'DeletedRequest'
end
2 changes: 0 additions & 2 deletions lib/models/deleted_request_raw_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
class DeletedRequestRawConfig < Model
belongs_to :repository
self.primary_key = 'id'
# has_many :request_raw_configurations
# has_many :deleted_request_raw_configurations
end
2 changes: 0 additions & 2 deletions lib/models/deleted_request_yaml_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
class DeletedRequestYamlConfig < Model
belongs_to :repository
self.primary_key = 'id'
# has_many :requests, foreign_key: :yaml_config_id, class_name: 'Request'
# has_many :deleted_requests, foreign_key: :yaml_config_id, class_name: 'DeletedRequest'
end
2 changes: 0 additions & 2 deletions lib/models/deleted_stage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,4 @@
class DeletedStage < Model
belongs_to :build
self.primary_key = 'id'
# has_many :jobs
# has_many :deleted_jobs
end
6 changes: 0 additions & 6 deletions lib/models/deleted_tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,4 @@ class DeletedTag < Model
belongs_to :last_build, foreign_key: :last_build_id, class_name: 'Build'
belongs_to :repository
self.primary_key = 'id'
# has_many :builds
# has_many :commits
# has_many :requests
# has_many :deleted_builds
# has_many :deleted_commits
# has_many :deleted_requests
end
Loading