-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_database.rb
64 lines (52 loc) · 1.19 KB
/
create_database.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
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
63
64
require 'rubygems'
require 'data_mapper'
# Connect to the database
# TODO - put back
#DataMapper.setup(:default, ENV['DATABASE_URL'] || 'mysql://kiwiwiki:[email protected]/kiwiwiki')
DataMapper.setup(:default, 'mysql://root:nemo451s@localhost/kiwiwiki')
# Define tables
require 'db_schema.rb'
# Automatically create the tables if they don't exist
DataMapper.auto_migrate!
# Define root category...
root = Categories.new
root.attributes = {
:id => 1,
:name => 'ROOT',
:parent => 0,
:deleted => false
}
# ...and save it to the database
root.save
#TODO - remove
# Define some test categories...
category1 = Categories.new
category1.attributes = {
:id => 2,
:name => 'Test',
:parent => 1,
:deleted => false
}
# ...and save it to the database
category1.save
# Define some test pages...
page1 = Pages.new
page1.attributes = {
:id => 1,
:name => 'TestPage',
:parent => 2,
:deleted => false,
:current_revision => 1
}
# ...and save it to the database
page1.save
# Define some test page revisions...
pagerev1 = Page_revisions.new
pagerev1.attributes = {
:id => 1,
:parent => 1,
:create_time => DateTime.now,
:text => "test text"
}
# ...and save it to the database
pagerev1.save