Class: PgOnlineSchemaChange::Client
- Inherits:
-
Object
- Object
- PgOnlineSchemaChange::Client
- Defined in:
- lib/pg_online_schema_change/client.rb
Instance Attribute Summary collapse
-
#alter_statement ⇒ Object
Returns the value of attribute alter_statement.
-
#connection ⇒ Object
Returns the value of attribute connection.
-
#copy_statement ⇒ Object
Returns the value of attribute copy_statement.
-
#dbname ⇒ Object
Returns the value of attribute dbname.
-
#delta_count ⇒ Object
Returns the value of attribute delta_count.
-
#drop ⇒ Object
Returns the value of attribute drop.
-
#host ⇒ Object
Returns the value of attribute host.
-
#kill_backends ⇒ Object
Returns the value of attribute kill_backends.
-
#password ⇒ Object
Returns the value of attribute password.
-
#port ⇒ Object
Returns the value of attribute port.
-
#pull_batch_count ⇒ Object
Returns the value of attribute pull_batch_count.
-
#schema ⇒ Object
Returns the value of attribute schema.
-
#skip_foreign_key_validation ⇒ Object
Returns the value of attribute skip_foreign_key_validation.
-
#table ⇒ Object
Returns the value of attribute table.
-
#table_name ⇒ Object
Returns the value of attribute table_name.
-
#username ⇒ Object
Returns the value of attribute username.
-
#wait_time_for_lock ⇒ Object
Returns the value of attribute wait_time_for_lock.
Instance Method Summary collapse
- #checkout_connection ⇒ Object
- #handle_copy_statement(statement) ⇒ Object
- #handle_validations ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
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 |
# File 'lib/pg_online_schema_change/client.rb', line 25 def initialize() @alter_statement = .alter_statement @schema = .schema @dbname = .dbname @host = .host @username = .username @port = .port @password = .password @drop = .drop @kill_backends = .kill_backends @wait_time_for_lock = .wait_time_for_lock @pull_batch_count = .pull_batch_count @delta_count = .delta_count @skip_foreign_key_validation = .skip_foreign_key_validation handle_copy_statement(.copy_statement) handle_validations @connection = PG.connect(dbname: @dbname, host: @host, user: @username, password: @password, port: @port) @table = Query.table(@alter_statement) @table_name = Query.table_name(@alter_statement, @table) PgOnlineSchemaChange.logger.debug("Connection established") end |
Instance Attribute Details
#alter_statement ⇒ Object
Returns the value of attribute alter_statement.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def alter_statement @alter_statement end |
#connection ⇒ Object
Returns the value of attribute connection.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def connection @connection end |
#copy_statement ⇒ Object
Returns the value of attribute copy_statement.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def copy_statement @copy_statement end |
#dbname ⇒ Object
Returns the value of attribute dbname.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def dbname @dbname end |
#delta_count ⇒ Object
Returns the value of attribute delta_count.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def delta_count @delta_count end |
#drop ⇒ Object
Returns the value of attribute drop.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def drop @drop end |
#host ⇒ Object
Returns the value of attribute host.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def host @host end |
#kill_backends ⇒ Object
Returns the value of attribute kill_backends.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def kill_backends @kill_backends end |
#password ⇒ Object
Returns the value of attribute password.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def password @password end |
#port ⇒ Object
Returns the value of attribute port.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def port @port end |
#pull_batch_count ⇒ Object
Returns the value of attribute pull_batch_count.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def pull_batch_count @pull_batch_count end |
#schema ⇒ Object
Returns the value of attribute schema.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def schema @schema end |
#skip_foreign_key_validation ⇒ Object
Returns the value of attribute skip_foreign_key_validation.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def skip_foreign_key_validation @skip_foreign_key_validation end |
#table ⇒ Object
Returns the value of attribute table.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def table @table end |
#table_name ⇒ Object
Returns the value of attribute table_name.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def table_name @table_name end |
#username ⇒ Object
Returns the value of attribute username.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def username @username end |
#wait_time_for_lock ⇒ Object
Returns the value of attribute wait_time_for_lock.
7 8 9 |
# File 'lib/pg_online_schema_change/client.rb', line 7 def wait_time_for_lock @wait_time_for_lock end |
Instance Method Details
#checkout_connection ⇒ Object
75 76 77 |
# File 'lib/pg_online_schema_change/client.rb', line 75 def checkout_connection PG.connect(dbname: dbname, host: host, user: username, password: password, port: port) end |
#handle_copy_statement(statement) ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/pg_online_schema_change/client.rb', line 66 def handle_copy_statement(statement) return if statement.nil? || statement == "" file_path = File.(statement) raise Error, "File not found: #{file_path}" unless File.file?(file_path) @copy_statement = File.binread(file_path) end |
#handle_validations ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/pg_online_schema_change/client.rb', line 52 def handle_validations unless Query.alter_statement?(@alter_statement) raise Error, "Not a valid ALTER statement: #{@alter_statement}" end if delta_count > pull_batch_count raise Error, "Value for delta_count should be smaller than the value for pull_batch_count" end return if Query.same_table?(@alter_statement) raise Error, "All statements should belong to the same table: #{@alter_statement}" end |