Class: Sequel::ReadyMaker
- Inherits:
-
Object
- Object
- Sequel::ReadyMaker
- Defined in:
- lib/sequel/extensions/make_readyable.rb
Overview
ReadyMaker
Internal class that handles the actual database preparation logic. This class processes the make_ready options and executes the necessary SQL statements to set up schemas, views, and external data sources.
Defined Under Namespace
Classes: FileSourcerer
Instance Attribute Summary collapse
-
#db ⇒ Sequel::Database
readonly
The database instance.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Instance Method Summary collapse
-
#create_view(source, table, schema) ⇒ Object
Creates a temporary view for the given table.
-
#get_source(db, schema) ⇒ Sequel::Database, FileSourcerer
Gets the appropriate source handler for the schema.
-
#initialize(db, opts) ⇒ ReadyMaker
constructor
Creates a new ReadyMaker instance.
-
#run ⇒ Object
Executes the database preparation process.
Constructor Details
#initialize(db, opts) ⇒ ReadyMaker
Creates a new ReadyMaker instance.
71 72 73 74 |
# File 'lib/sequel/extensions/make_readyable.rb', line 71 def initialize(db, opts) @db = db @opts = opts end |
Instance Attribute Details
#db ⇒ Sequel::Database (readonly)
65 66 67 |
# File 'lib/sequel/extensions/make_readyable.rb', line 65 def db @db end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
65 |
# File 'lib/sequel/extensions/make_readyable.rb', line 65 attr_reader :db, :opts |
Instance Method Details
#create_view(source, table, schema) ⇒ Object
Creates a temporary view for the given table.
110 111 112 113 114 115 116 117 118 |
# File 'lib/sequel/extensions/make_readyable.rb', line 110 def create_view(source, table, schema) if schema.to_s =~ %r{/} source.create_view(table, temp: true) else # For schema-based tables, just create temporary views # This extension is primarily for Spark SQL-based databases source.create_view(table, db[Sequel.qualify(schema, table)], temp: true) end end |
#get_source(db, schema) ⇒ Sequel::Database, FileSourcerer
Gets the appropriate source handler for the schema.
125 126 127 128 129 130 131 |
# File 'lib/sequel/extensions/make_readyable.rb', line 125 def get_source(db, schema) if schema.to_s =~ %r{/} FileSourcerer.new(db, Pathname.new(schema.to_s)) else db end end |
#run ⇒ Object
Executes the database preparation process.
This method handles:
-
Setting the primary schema if specified
-
Processing the search path to create views
-
Handling table filtering (only/except options)
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/sequel/extensions/make_readyable.rb', line 82 def run if opts[:use_schema] db.extension :usable db.use(opts[:use_schema]) end only_tables = Array(opts[:only]) created_views = Array(opts[:except]) || [] (opts[:search_path] || []).flatten.each do |schema| schema = schema.to_sym unless schema.is_a?(Pathname) source = get_source(db, schema) tables = if schema.is_a?(Pathname) source.tables - created_views else source.tables(schema: schema) - created_views end tables &= only_tables unless only_tables.empty? tables.each do |table| create_view(source, table, schema) created_views << table end end end |