Class: SQLGenerator::SqliteGenerator

Inherits:
SQLGenerator
  • Object
show all
Defined in:
lib/convergence/sql_generator/sqlite_generator.rb

Overview

SQLite's ALTER TABLE support is intentionally limited: it can add/drop columns and create/drop indexes, but it cannot change a column's type/null/default, nor add/remove a foreign key or primary key on an existing table. Doing any of those requires SQLite's official "rebuild the table" procedure (create a new table, copy the data over, drop the old one, rename), which this adapter does not implement yet -- it raises NotImplementedError instead of generating SQL that SQLite would reject.

Constant Summary collapse

UNSUPPORTED_TYPES =
[:enum, :set].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#original_tableObject (readonly)

Returns the value of attribute original_table.



13
14
15
# File 'lib/convergence/sql_generator/sqlite_generator.rb', line 13

def original_table
  @original_table
end

Instance Method Details

#generate(to_table, delta, original_table, safe_migration: false) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/convergence/sql_generator/sqlite_generator.rb', line 15

def generate(to_table, delta, original_table, safe_migration: false)
  @original_table = original_table
  sqls = []
  sqls << rename_table_sqls(delta)
  sqls << change_table_sql(to_table, delta)
  sqls << (safe_migration ? [] : drop_table_sqls(delta))
  sqls << create_table_sqls(delta)
  sqls.reject!(&:empty?)
  sqls.join("\n")
end