Class: PgEasyReplicate::Group
- Inherits:
-
Object
- Object
- PgEasyReplicate::Group
show all
- Extended by:
- Helper
- Defined in:
- lib/pg_easy_replicate/group.rb
Class Method Summary
collapse
Methods included from Helper
abort_with, connection_info, db_name, db_user, determine_tables, internal_schema_name, internal_user_name, list_all_tables, logger, publication_name, quote_ident, secondary_source_db_url, source_db_url, subscription_name, target_db_url, test_env?, underscore
Class Method Details
.create(options) ⇒ Object
40
41
42
43
44
45
46
47
48
49
50
|
# File 'lib/pg_easy_replicate/group.rb', line 40
def create(options)
groups.insert(
name: options[:name],
table_names: options[:table_names],
schema_name: options[:schema_name],
started_at: options[:started_at],
failed_at: options[:failed_at],
)
rescue => e
abort_with("Adding group entry failed: #{e.message}")
end
|
.delete(group_name) ⇒ Object
75
76
77
78
79
|
# File 'lib/pg_easy_replicate/group.rb', line 75
def delete(group_name)
groups.where(name: group_name).delete
rescue => e
abort_with("Deleting group entry failed: #{e.message}")
end
|
.drop ⇒ Object
30
31
32
33
34
35
36
37
38
|
# File 'lib/pg_easy_replicate/group.rb', line 30
def drop
conn =
Query.connect(
connection_url: source_db_url,
schema: internal_schema_name,
).drop_table?("groups")
ensure
conn&.disconnect
end
|
.find(group_name) ⇒ Object
69
70
71
72
73
|
# File 'lib/pg_easy_replicate/group.rb', line 69
def find(group_name)
groups.first(name: group_name)
rescue => e
abort_with("Finding group entry failed: #{e.message}")
end
|
.setup ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/pg_easy_replicate/group.rb', line 7
def setup
conn =
Query.connect(
connection_url: source_db_url,
schema: internal_schema_name,
)
return if conn.table_exists?("groups")
conn.create_table("groups") do
primary_key(:id)
column(:name, String, null: false)
column(:table_names, String, text: true)
column(:schema_name, String)
column(:created_at, Time, default: Sequel::CURRENT_TIMESTAMP)
column(:updated_at, Time, default: Sequel::CURRENT_TIMESTAMP)
column(:started_at, Time)
column(:failed_at, Time)
column(:recreate_indices_post_copy, TrueClass, default: true)
column(:switchover_completed_at, Time)
end
ensure
conn&.disconnect
end
|
.update(group_name:, started_at: nil, switchover_completed_at: nil, failed_at: nil) ⇒ Object
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/pg_easy_replicate/group.rb', line 52
def update(
group_name:,
started_at: nil,
switchover_completed_at: nil,
failed_at: nil
)
set = {
started_at: started_at&.utc,
switchover_completed_at: switchover_completed_at&.utc,
failed_at: failed_at&.utc,
updated_at: Time.now.utc,
}.compact
groups.where(name: group_name).update(set)
rescue => e
abort_with("Updating group entry failed: #{e.message}")
end
|