Skip to content

Commit

Permalink
New database files.
Browse files Browse the repository at this point in the history
  • Loading branch information
davorg committed Dec 19, 2015
1 parent db6756e commit 1739eab
Show file tree
Hide file tree
Showing 5 changed files with 110 additions and 0 deletions.
19 changes: 19 additions & 0 deletions db/make_ddl
@@ -0,0 +1,19 @@
#!/usr/bin/perl

use strict;
use warnings;

use FindBin qw($Bin);
use lib "$Bin/../Shrtr/lib";
use Getopt::Long;
use Shrtr::Schema;

my $preversion;
GetOptions('p|preversion:s' => \$preversion)
or die;

my $sch = Shrtr::Schema->connect('dbi:SQLite:db=shrtr.db');

my $sqldir = "$Bin/sql";
my $version = $sch->schema_version;
$sch->create_ddl_dir('SQLite', $version, $sqldir, $preversion);
4 changes: 4 additions & 0 deletions db/sql/Shrtr-Schema-0.001-0.001-SQLite.sql
@@ -0,0 +1,4 @@
-- Convert schema '/home/dave/git/shrtr/db/sql/Shrtr-Schema-0.001-SQLite.sql' to '/home/dave/git/shrtr/db/sql/Shrtr-Schema-0.001-SQLite.sql':;

-- No differences found;

69 changes: 69 additions & 0 deletions db/sql/Shrtr-Schema-0.001-SQLite.sql
@@ -0,0 +1,69 @@
--
-- Created by SQL::Translator::Producer::SQLite
-- Created on Sat Feb 9 20:39:27 2013
--

BEGIN TRANSACTION;

--
-- Table: click
--
DROP TABLE click;

CREATE TABLE click (
id INTEGER PRIMARY KEY NOT NULL,
url integer NOT NULL,
ts timestamp NOT NULL DEFAULT current_timestamp,
referrer varchar(200),
user_agent varchar(200),
ip_address varchar(15),
FOREIGN KEY (url) REFERENCES url(id) ON DELETE CASCADE ON UPDATE CASCADE
);

CREATE INDEX click_idx_url ON click (url);

--
-- Table: url
--
DROP TABLE url;

CREATE TABLE url (
id INTEGER PRIMARY KEY NOT NULL,
code varchar(200),
url text,
ts timestamp NOT NULL DEFAULT current_timestamp
);

CREATE UNIQUE INDEX code ON url (code);

--
-- Table: user
--
DROP TABLE user;

CREATE TABLE user (
id INTEGER PRIMARY KEY NOT NULL,
username varchar(20) NOT NULL,
email varchar(100) NOT NULL,
password varchar(32) NOT NULL
);

--
-- Table: user_url
--
DROP TABLE user_url;

CREATE TABLE user_url (
user integer,
url integer,
ts timestamp NOT NULL DEFAULT current_timestamp,
ip varchar(15),
FOREIGN KEY (url) REFERENCES url(id) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY (user) REFERENCES user(id) ON DELETE CASCADE ON UPDATE CASCADE
);

CREATE INDEX user_url_idx_url ON user_url (url);

CREATE INDEX user_url_idx_user ON user_url (user);

COMMIT;
18 changes: 18 additions & 0 deletions db/upgrade
@@ -0,0 +1,18 @@
#!/usr/bin/perl

use strict;
use warnings;
use 5.010;

use FindBin '$Bin';
use lib "$Bin/../Shrtr/lib";
use Shrtr::Schema;

my $sch = Shrtr::Schema->connect('dbi:SQLite:db=shrtr.db');

if ($sch->get_db_version) {
$sch->upgrade;
} else {
$sch->deploy;
}

Binary file added shrtr.db
Binary file not shown.

0 comments on commit 1739eab

Please sign in to comment.