instiki/lib/db_structure.rb

47 lines
950 B
Ruby
Raw Normal View History

2005-08-02 09:58:22 +02:00
require 'erb'
def create_options
if @db == 'mysql'
'ENGINE = ' + (mysql_engine rescue @mysql_engine)
end
end
2005-08-09 04:20:28 +02:00
def db_quote(column)
case @db
when 'postgresql'
return "\"#{column}\""
when 'sqlite', 'sqlite3'
return "'#{column}'"
when 'mysql'
return "`#{column}`"
end
end
2005-08-02 09:58:22 +02:00
def db_structure(db)
db.downcase!
@db = db
case db
when 'postgresql'
@pk = 'SERIAL PRIMARY KEY'
@datetime = 'TIMESTAMP'
2005-08-09 04:20:28 +02:00
@boolean = "BOOLEAN"
2005-08-02 09:58:22 +02:00
when 'sqlite', 'sqlite3'
@pk = 'INTEGER PRIMARY KEY'
@datetime = 'DATETIME'
2005-08-09 04:20:28 +02:00
@boolean = "INTEGER"
2005-08-02 09:58:22 +02:00
when 'mysql'
@pk = 'INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY'
@datetime = 'DATETIME'
2005-08-09 04:20:28 +02:00
@boolean = "TINYINT"
2005-08-02 09:58:22 +02:00
@mysql_engine = 'InnoDB'
else
raise "Unknown db type #{db}"
end
s = ''
Dir[RAILS_ROOT + '/db/*.erbsql'].each do |filename|
2005-08-02 09:58:22 +02:00
s += ERB.new(File.read(filename)).result
end
s
end