summary refs log tree commit diff
path: root/scripts/migrate_from_redis.pl
blob: 61490c11e32aba292c5e25d8d96cb60d1a8629fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/env perl
use strict;
use warnings;

use jitterbug::Schema;

use YAML qw/LoadFile/;
use JSON;

my $conf = shift || die "config is missing";
my $data = shift || die "data is missing";

$conf = LoadFile($conf);
$data = LoadFile($data);

my $schema = jitterbug::Schema->connect(
    @{ $conf->{plugins}->{DBIC}->{schema}->{connect_info} } );

my $project = $schema->resultset('Project')->create(
    {
        name        => $data->{desc}->{name},
        url         => $data->{desc}->{url},
        description => $data->{desc}->{description},
        owner       => JSON::encode_json( $data->{desc}->{owner} ),
    }
);

foreach my $build ( @{ $data->{builds} } ) {
    my $sha256    = delete $build->{commit};
    my $timestamp = $build->{timestamp};
    my $tests = delete $build->{version};
    $build->{build}->{version} = $tests;
    $schema->resultset('Commit')->create(
        {
            sha256    => $sha256,
            projectid => $project->projectid,
            timestamp => $timestamp,
            content   => JSON::encode_json($build),
        }
    );
}