OSDN Git Service

Model::Base: remove deprecated / unused functions
[newslash/newslash.git] / src / newslash_web / lib / Newslash / Model / Histories.pm
1 package Newslash::Model::Histories;
2 use Newslash::Model::Base -base;
3
4 use constant HISTORY_TABLE_NAME => 'ns_histories';
5
6 sub on_start_up {
7     my $self = shift;
8
9     # create tables
10     return 1 if $self->check_readonly;
11
12     my $table_name = HISTORY_TABLE_NAME;
13
14     # under construction...
15     return 1;
16
17     if (!$self->table_exists($table_name)) {
18         my $dbh = $self->connect_db;
19
20         my $sql = <<"EOSQL";
21 CREATE TABLE IF NOT EXISTS $table_name (
22   history_id  mediumint(8) unsigned AUTO_INCREMENT PRIMARY KEY,
23   type        varchar(128) NOT NULL,
24   status      varchar(128),
25   uid         mediumint(8) unsigned NOT NULL,
26   format      varchar(128),
27   title       mediumtext,
28   introtext   mediumtext,
29   bodytext    mediumtext,
30   relatedtext mediumtext,
31   dept        mediumtext,
32   tags        mediumtext,
33   related_id  mediumint(8) unsigned NOT NULL,
34   timestamp   timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
35 ) DEFAULT CHARSET=utf8mb4
36 EOSQL
37         my $rs = $dbh->do($sql, undef);
38         $self->disconnect_db;
39         if ($rs) {
40             $self->warn("create table: $table_name");
41         }
42         else {
43             $self->warn("cannot create table: $table_name");
44         }
45     }
46
47     return 1;
48 }
49