Pics common module. Using Rose::Object generic methods generator instead of raw perl...
[blog.pm-common-perl-mods.git] / Common-RDBO-Helper / t / lib / NewDB.pm
blob951a9a654ef11969e3b2807ef99cd53f78562324
1 package NewDB;
3 use DBI;
5 sub new {
6 my $class = shift;
8 my $self = { db => "/tmp/common-rdbo-helper.db" };
10 bless $self, $class;
12 return $self;
15 sub init {
16 my $self = shift;
18 my $db = $self->{ db };
20 unless ( -f $db ) {
21 warn 'Creating new db...';
23 my $dbh = DBI->connect( "dbi:SQLite:$db" ) or die $DBI::errstr;
25 $dbh->do( <<SQL );
26 CREATE TABLE `post` (
27 `id` INTEGER PRIMARY KEY NOT NULL,
28 `addtime` INTEGER NOT NULL,
29 `title` VARCHAR(255) NOT NULL,
30 `content` VARCHAR(255) NOT NULL
32 SQL
34 $dbh->do( <<SQL );
35 CREATE TABLE `article` (
36 `id` INTEGER PRIMARY KEY NOT NULL,
37 `addtime` INTEGER NOT NULL,
38 `title` VARCHAR(255) NOT NULL,
39 `content` VARCHAR(255) NOT NULL
41 SQL
43 $dbh->do( <<SQL );
44 CREATE TABLE tag (
45 id INTEGER PRIMARY KEY NOT NULL,
46 name VARCHAR NOT NULL,
47 UNIQUE(name)
49 SQL
51 $dbh->do( <<SQL );
52 CREATE TABLE post_tag_map (
53 post_id INTEGER KEY NOT NULL,
54 tag_id INTEGER NOT NULL,
55 PRIMARY KEY(post_id, tag_id)
57 SQL
59 $dbh->do( <<SQL );
60 CREATE TABLE comment (
61 id INTEGER PRIMARY KEY NOT NULL,
62 master_id INTEGER NOT NULL,
63 type VARCHAR,
64 user_id INTEGER,
65 `addtime` INTEGER NOT NULL,
66 name VARCHAR,
67 url VARCHAR,
68 email VARCHAR,
69 content TEXT NOT NULL
71 SQL
73 $dbh->do( <<SQL );
74 CREATE TABLE pic (
75 id INTEGER PRIMARY KEY NOT NULL,
76 master_id INTEGER NOT NULL,
77 type VARCHAR,
78 user_id INTEGER,
79 `addtime` INTEGER NOT NULL,
80 pic VARCHAR
82 SQL
84 $dbh->disconnect();
88 sub cleanup {
89 my $self = shift;
91 unlink $self->{ db };
94 =head1 AUTHOR
96 vti
98 =head1 LICENSE
100 This library is free software, you can redistribute it and/or modify
101 it under the same terms as Perl itself.
103 =cut