Skip to content

Commit

Permalink
chore: make metadata queries compatible with named schemas (#296)
Browse files Browse the repository at this point in the history
  • Loading branch information
olavloite committed Feb 5, 2024
1 parent c938ccc commit c6f85d1
Show file tree
Hide file tree
Showing 15 changed files with 337 additions and 281 deletions.
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,6 @@ Style/WordArray:
Style/RegexpLiteral:
Enabled: false
Metrics/MethodLength:
Max: 40
Max: 60
Metrics/BlockLength:
Max: 30
2 changes: 1 addition & 1 deletion benchmarks/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
require_relative "models/album"

class Application
def self.run # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def self.run # rubocop:disable Metrics/AbcSize
ActiveRecord::Base.logger.level = Logger::WARN
config = ActiveRecord::Base.connection_config
spanner = Google::Cloud::Spanner.new project: config[:project], credentials: config[:credentials]
Expand Down
2 changes: 1 addition & 1 deletion examples/snippets/read-only-transactions/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
require_relative "models/album"

class Application
def self.run # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
def self.run # rubocop:disable Metrics/AbcSize
# Use a read-only transaction to execute multiple reads at the same commit timestamp.
# The Spanner ActiveRecord adapter supports the custom isolation level :read_only that
# will start a read-only Spanner transaction with a strong timestamp bound.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class SchemaCreation < SchemaCreation
private

# rubocop:disable Naming/MethodName, Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
# rubocop:disable Metrics/MethodLength

def visit_TableDefinition o
create_sql = +"CREATE TABLE #{quote_table_name o.name} "
Expand Down Expand Up @@ -133,7 +132,6 @@ def visit_IndexDefinition o
end

# rubocop:enable Naming/MethodName, Metrics/AbcSize, Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
# rubocop:enable Metrics/MethodLength

def add_column_options! column, sql, options
if options[:null] == false || options[:primary_key] == true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,15 @@ def table_exists? table_name
end
alias data_source_exists? table_exists?

def extract_schema_qualified_name string
schema, name = string.to_s.scan(/[^`.\s]+|`[^`]*`/)
unless name
name = schema
schema = nil
end
[schema, name]
end

def create_table table_name, id: :primary_key, **options
td = create_table_definition table_name, options

Expand Down
8 changes: 6 additions & 2 deletions lib/activerecord_spanner_adapter/foreign_key.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

module ActiveRecordSpannerAdapter
class ForeignKey
attr_accessor :table_name, :name, :columns, :ref_table, :ref_columns,
attr_accessor :table_schema, :table_name, :name, :columns, :ref_schema, :ref_table, :ref_columns,
:on_delete, :on_update

def initialize \
Expand All @@ -16,10 +16,14 @@ def initialize \
ref_table,
ref_columns,
on_delete: nil,
on_update: nil
on_update: nil,
table_schema: "",
ref_schema: ""
@table_schema = table_schema
@table_name = table_name
@name = name
@columns = Array(columns)
@ref_schema = ref_schema
@ref_table = ref_table
@ref_columns = Array(ref_columns)
@on_delete = on_delete unless on_delete == "NO ACTION"
Expand Down
6 changes: 4 additions & 2 deletions lib/activerecord_spanner_adapter/index.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

module ActiveRecordSpannerAdapter
class Index
attr_accessor :table, :name, :columns, :type, :unique, :null_filtered,
attr_accessor :schema, :table, :name, :columns, :type, :unique, :null_filtered,
:interleave_in, :storing, :state

def initialize \
Expand All @@ -20,7 +20,9 @@ def initialize \
null_filtered: false,
interleave_in: nil,
storing: nil,
state: nil
state: nil,
schema: ""
@schema = schema.to_s
@table = table.to_s
@name = name.to_s
@columns = Array(columns)
Expand Down
4 changes: 3 additions & 1 deletion lib/activerecord_spanner_adapter/index/column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
module ActiveRecordSpannerAdapter
class Index
class Column
attr_accessor :table_name, :index_name, :name, :order, :ordinal_position
attr_accessor :table_name, :schema_name, :index_name, :name, :order, :ordinal_position

def initialize \
table_name,
index_name,
name,
schema_name: "",
order: nil,
ordinal_position: nil
@table_name = table_name.to_s
@index_name = index_name.to_s
@schema_name = schema_name.to_s
@name = name.to_s
@order = order.to_s.upcase if order
@ordinal_position = ordinal_position
Expand Down
Loading

0 comments on commit c6f85d1

Please sign in to comment.