Skip to content

Commit

Permalink
fix setup_database
Browse files Browse the repository at this point in the history
  • Loading branch information
yuki-kimoto committed Apr 21, 2016
1 parent 9922ae2 commit 1f37e43
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 30 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ If you used Gitprep version 1 from now, you need upgrade database.

mv data/gitprep.db data/gitprep_v1bak.db
./setup_database
./copy_database_v1_to_v2 data/gitprep_v1bak.db data/gitprep.db
old/copy_database_v1_to_v2 data/gitprep_v1bak.db data/gitprep.db

If you install git in your local directry,
you must add the correct git command path to the **gitprep.conf** config file.
Expand Down
30 changes: 1 addition & 29 deletions lib/Gitprep/Manager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,6 @@ EOS
# Create pull_request columns
my @pull_request_columns = (
"title not null default ''",
"message not null default ''",
"open integer default 0",
"open_time integer default 0",
"open_user integer default 0"
Expand All @@ -574,39 +573,12 @@ EOS
}

# Check pull_request table
eval { $dbi->select([qw/row_id project branch1 branch2 title message open open_time open_user/], table => 'pull_request') };
eval { $dbi->select([qw/row_id project branch1 branch2 title open open_time open_user/], table => 'pull_request') };
if ($@) {
my $error = "Can't create pull_request table properly: $@";
$self->app->log->error($error);
croak $error;
}

# Create number table
eval {
my $sql = <<"EOS";
create table number (
row_id integer primary key autoincrement,
key not null unique
);
EOS
$dbi->execute($sql);
};

# Create number columns
my $number_columns = [
"value integer not null default '0'"
];
for my $column (@$number_columns) {
eval { $dbi->execute("alter table number add column $column") };
}

# Check number table
eval { $dbi->select([qw/row_id key value/], table => 'number') };
if ($@) {
my $error = "Can't create number table properly: $@";
$self->app->log->error($error);
croak $error;
}
}

=pod
Expand Down
38 changes: 38 additions & 0 deletions old/copy_database_v1_to_v2
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env perl

use FindBin;
use lib "$FindBin::Bin/../extlib/lib/perl5";
use DBIx::Custom;

my ($old_database_file, $new_database_file) = @ARGV;

# Old DBI
my %old_dbi_args = (
dsn => "dbi:SQLite:database=$old_database_file",
connector => 1,
option => {sqlite_unicode => 1, sqlite_use_immediate_transaction => 1}
);
my $old_dbi = DBIx::Custom->connect(%old_dbi_args);

# New DBI
my %new_dbi_args = (
dsn => "dbi:SQLite:database=$new_database_file",
connector => 1,
option => {sqlite_unicode => 1, sqlite_use_immediate_transaction => 1}
);
my $new_dbi = DBIx::Custom->connect(%new_dbi_args);

# Copy number data
my $numbers = $old_dbi->select(table => 'number')->all;
for my $number (@$numbers) {
$new_dbi->insert($number, table => 'number');
}

=pod
collaboration
number
project
pull_request
ssh_public_key
user
=cut

0 comments on commit 1f37e43

Please sign in to comment.