<commit_before>#!/usr/bin/env perl
use strict;
use warnings;
use JSON::XS;
use Storable qw(thaw);
use DBI;
use VRPipe;

warn "I will alter this database: ", VRPipe::Persistent::SchemaBase->get_dsn, " [ctrl-c now to abort]\n";
sleep(3);

my $json  = JSON::XS->new->utf8->canonical;
my $dbh   = DBI->connect(VRPipe::Persistent::SchemaBase->get_dsn, VRPipe::Persistent::SchemaBase->get_user, VRPipe::Persistent::SchemaBase->get_password, { RaiseError => 1, AutoCommit => 0 }) or die $DBI::errstr;
my $limit = 10000;

warn "\n ## First, I'll do in-place updates of columns containing Storable values, converting them to JSON values\n\n";
foreach ([qw(Job output_files)], [qw(Step options_definition inputs_definition outputs_definition)], [qw(DataSource options)], [qw(PipelineSetup options)], [qw(Requirements custom)], [qw(StepAdaptor adaptor_hash)], [qw(StepIODefinition metadata)]) {
    my ($table, @cols) = @$_;
    my $class = "VRPipe::$table";
    $table = lc($table);
    
    my $sth = $dbh->prepare("update $table set " . join(", ", map { "`$_` = ?" } @cols) . " where id = ?");
    warn "Will update table $table, columns ", join(", ", @cols), "\n";
    
    my $offset = 0;
    while (1) {
        my $select = $dbh->prepare("SELECT id, " . join(", ", @cols) . " FROM $table LIMIT $offset, $limit");
        $select->execute;
        
        my $count = 0;
        eval {
            while (my $row = $select->fetch) {<commit_msg>also in-place convert the ArrayRef columns<commit_after>#!/usr/bin/env perl
use strict;
use warnings;
use JSON::XS;
use Storable qw(thaw);
use DBI;
use VRPipe;

warn "I will alter this database: ", VRPipe::Persistent::SchemaBase->get_dsn, " [ctrl-c now to abort]\n";
sleep(3);

my $json  = JSON::XS->new->utf8->canonical;
my $dbh   = DBI->connect(VRPipe::Persistent::SchemaBase->get_dsn, VRPipe::Persistent::SchemaBase->get_user, VRPipe::Persistent::SchemaBase->get_password, { RaiseError => 1, AutoCommit => 0 }) or die $DBI::errstr;
my $limit = 10000;

warn "\n ## First, I'll do in-place updates of columns containing Storable values, converting them to JSON values\n\n";
foreach ([qw(Job output_files)], [qw(Step options_definition inputs_definition outputs_definition)], [qw(DataSource options)], [qw(PipelineSetup options)], [qw(Requirements custom)], [qw(StepAdaptor adaptor_hash)], [qw(StepIODefinition metadata)], [qw(StepBehaviour behaviour_array)], [qw(StepOption allowed_values)]) {
    my ($table, @cols) = @$_;
    my $class = "VRPipe::$table";
    $table = lc($table);
    
    my $sth = $dbh->prepare("update $table set " . join(", ", map { "`$_` = ?" } @cols) . " where id = ?");
    warn "Will update table $table, columns ", join(", ", @cols), "\n";
    
    my $offset = 0;
    while (1) {
        my $select = $dbh->prepare("SELECT id, " . join(", ", @cols) . " FROM $table LIMIT $offset, $limit");
        $select->execute;
        
        my $count = 0;
        eval {
            while (my $row = $select->fetch) {
{'fraction_non_alphanumeric': 0.17891910036925143, 'fraction_numerical': 0.008056394763343404, 'mean_word_length': 3.9584026622296173, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5750863', 'n_tokens_mistral': 1053, 'n_tokens_neox': 1017, 'n_words': 271}