Class: SlashMigrate::SchemaInspector

Inherits:
Object
  • Object
show all
Defined in:
app/services/slash_migrate/schema_inspector.rb

Overview

Reads the live database schema through the Active Record connection. This is the single source of truth the rest of the engine builds on: the table browser renders from it, and the migration builder relies on it to know the current type/default/index of a column so every generated migration can be made reversible.

Defined Under Namespace

Classes: Table

Constant Summary collapse

INTERNAL_TABLES =

Active Record’s own bookkeeping tables. Never shown or touched.

%w[schema_migrations ar_internal_metadata].freeze

Instance Method Summary collapse

Instance Method Details

#exists?(name) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'app/services/slash_migrate/schema_inspector.rb', line 15

def exists?(name)
  table_names.include?(name.to_s)
end

#table(name) ⇒ Object



19
20
21
# File 'app/services/slash_migrate/schema_inspector.rb', line 19

def table(name)
  Table.new(name.to_s, connection)
end

#table_namesObject



11
12
13
# File 'app/services/slash_migrate/schema_inspector.rb', line 11

def table_names
  (connection.tables - INTERNAL_TABLES).sort
end