Skip to content

Commit

Permalink
Implement DataStorage::DBI::SQLite.
Browse files Browse the repository at this point in the history
  • Loading branch information
hiratara committed Jun 16, 2012
1 parent a931c7a commit 3262e36
Show file tree
Hide file tree
Showing 24 changed files with 606 additions and 117 deletions.
46 changes: 46 additions & 0 deletions db/init_sqlite.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
--
-- Created by SQL::Translator::Producer::SQLite
-- Created on Wed Jun 13 22:58:42 2012
--

BEGIN TRANSACTION;

--
-- Table: post
--
CREATE TABLE post (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
text text NOT NULL,
tags varchar(331) NOT NULL DEFAULT '',
-- ex. | AA BB CC |
nickname varchar(32) NOT NULL,
user_key varchar(64) NOT NULL,
profile_image_url varchar(128) NOT NULL,
plusplus int(10) NOT NULL DEFAULT 0,
created_at_ms bigint(20) NOT NULL
);

--
-- Table: user
--
CREATE TABLE user (
user_key varchar(64) NOT NULL,
nickname varchar(32) NOT NULL,
profile_image_url varchar(128) NOT NULL,
sns_data_cache blob NOT NULL,
created_at datetime NOT NULL,
updated_at datetime NOT NULL,
PRIMARY KEY (user_key)
);

--
-- Table: session
--
CREATE TABLE session (
token varchar(64) NOT NULL,
user_key varchar(64) NOT NULL,
expire_at datetime NOT NULL,
PRIMARY KEY (token)
);

COMMIT;
36 changes: 36 additions & 0 deletions helper/mysql_to_sqlite.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env perl
use strict;
use warnings;
use File::Basename qw/dirname/;
use SQL::Translator;

my $dirname = dirname __FILE__;

my $translator = SQL::Translator->new;
my $sql_for_sqlite = $translator->translate(
from => 'MySQL',
to => 'SQLite',
filename => "$dirname/../db/init.sql",
) or die $translator->error;

# SQL::Translator doesn't output AUTOINCREMENT keyword,
# but we need it to pass t/002_data_storage_mysql.t.
$sql_for_sqlite =~ s/\b(INTEGER PRIMARY KEY)\b/$1 AUTOINCREMENT/g;

open my $out, '>', "$dirname/../db/init_sqlite.sql" or die $!;
print $out $sql_for_sqlite;

__END__
=encoding utf8
=head1 NAME
mysql_to_sqlite.pl - Translates from init.sql to init_sqlite.sql.
=head1 DESCRIPTION
This script is for authors. Please run this script when you change init.sql.
=cut
Loading

0 comments on commit 3262e36

Please sign in to comment.