28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/jun/active_record/migration.rb', line 28
def create_table(table_name, options = {})
sql = "CREATE TABLE IF NOT EXISTS #{table_name}"
column_options = []
if options[:id] || !options.key?(:id)
column_options << {
name: :id,
type: :integer,
primary_key: true,
null: false
}
end
column_options += options.fetch(:columns, [])
columns_sql = column_options.map do |column|
next(column) if column.is_a?(String)
column_sql = []
column_sql << column[:name]
column_sql << column[:type]&.to_s&.upcase
column_sql << "PRIMARY KEY" if column[:primary_key] == true
column_sql << "NOT NULL" if column[:null] == false
column_sql << "DEFAULT #{column[:default]}" if column[:default]
column_sql << "UNIQUE" if column[:unique] == true
column_sql.compact.join(" ")
end
sql += " (#{columns_sql.join(", ")})"
sql += ";"
execute(sql)
end
|