Initial database definitions
This commit is contained in:
parent
fdba99cb93
commit
21adee88d4
5 changed files with 82 additions and 0 deletions
30
config/database.yml
Normal file
30
config/database.yml
Normal file
|
@ -0,0 +1,30 @@
|
|||
# SQLite is enabled by default. Remember to change the dbfile path.
|
||||
production:
|
||||
adapter: sqlite
|
||||
dbfile: /tmp/instiki_prod.db
|
||||
|
||||
# Uncomment this section for MySQL:
|
||||
# production:
|
||||
# adapter: mysql
|
||||
# host: localhost
|
||||
# database: instiki
|
||||
# username: instiki
|
||||
# password: pass
|
||||
|
||||
# Uncomment this section for PostgreSQL:
|
||||
# production:
|
||||
# adapter: postgresql
|
||||
# host: localhost
|
||||
# database: instiki
|
||||
# username: instiki
|
||||
# password: pass
|
||||
|
||||
# The following settings are only used for testing and development.
|
||||
development:
|
||||
adapter: sqlite
|
||||
dbfile: /tmp/instiki_dev.db
|
||||
|
||||
test:
|
||||
adapter: sqlite
|
||||
dbfile: /tmp/instiki_test.db
|
||||
|
6
db/pages.erbsql
Normal file
6
db/pages.erbsql
Normal file
|
@ -0,0 +1,6 @@
|
|||
CREATE TABLE pages (
|
||||
id <%= @pk %>,
|
||||
created_at <%= @datetime %> NOT NULL,
|
||||
updated_at <%= @datetime %> NOT NULL,
|
||||
web_id INTEGER NOT NULL
|
||||
) <%= create_options %>;
|
7
db/revisions.erbsql
Normal file
7
db/revisions.erbsql
Normal file
|
@ -0,0 +1,7 @@
|
|||
CREATE TABLE revisions (
|
||||
id <%= @pk %>,
|
||||
created_at <%= @datetime %> NOT NULL,
|
||||
updated_at <%= @datetime %> NOT NULL,
|
||||
page_id INTEGER NOT NULL,
|
||||
content TEXT NOT NULL
|
||||
) <%= create_options %>;
|
7
db/webs.erbsql
Normal file
7
db/webs.erbsql
Normal file
|
@ -0,0 +1,7 @@
|
|||
CREATE TABLE pages (
|
||||
id <%= @pk %>,
|
||||
created_at <%= @datetime %> NOT NULL,
|
||||
updated_at <%= @datetime %> NOT NULL,
|
||||
name VARCHAR(60) NOT NULL,
|
||||
address VARCHAR(60) NOT NULL
|
||||
) <%= create_options %>;
|
32
lib/db_structure.rb
Normal file
32
lib/db_structure.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
require 'erb'
|
||||
|
||||
def create_options
|
||||
if @db == 'mysql'
|
||||
'ENGINE = ' + (mysql_engine rescue @mysql_engine)
|
||||
end
|
||||
end
|
||||
|
||||
def db_structure(db)
|
||||
db.downcase!
|
||||
@db = db
|
||||
case db
|
||||
when 'postgresql'
|
||||
@pk = 'SERIAL PRIMARY KEY'
|
||||
@datetime = 'TIMESTAMP'
|
||||
when 'sqlite', 'sqlite3'
|
||||
@pk = 'INTEGER PRIMARY KEY'
|
||||
@datetime = 'DATETIME'
|
||||
when 'mysql'
|
||||
@pk = 'INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY'
|
||||
@datetime = 'DATETIME'
|
||||
@mysql_engine = 'InnoDB'
|
||||
else
|
||||
raise "Unknown db type #{db}"
|
||||
end
|
||||
|
||||
s = ''
|
||||
Dir['db/*.erbsql'].each do |filename|
|
||||
s += ERB.new(File.read(filename)).result
|
||||
end
|
||||
s
|
||||
end
|
Loading…
Reference in a new issue