Fix #126 - Add a command to migrate data from SQLite to an other database
This commit is contained in:
parent
722ba6708b
commit
a4149b73ba
|
@ -13,6 +13,7 @@ Revision history for Lufi
|
||||||
- Add report file link in the navbar
|
- Add report file link in the navbar
|
||||||
- Allow to choose your language
|
- Allow to choose your language
|
||||||
- Use a recurrent task to provision shorts
|
- Use a recurrent task to provision shorts
|
||||||
|
- Add a command to migrate data from SQLite to an other database
|
||||||
|
|
||||||
0.02.2 2017-09-18
|
0.02.2 2017-09-18
|
||||||
- Fix cron tasks bug
|
- Fix cron tasks bug
|
||||||
|
|
1
cpanfile
1
cpanfile
|
@ -19,6 +19,7 @@ requires 'Filesys::DfPortable';
|
||||||
requires 'Data::Entropy';
|
requires 'Data::Entropy';
|
||||||
requires 'Crypt::SaltedHash';
|
requires 'Crypt::SaltedHash';
|
||||||
requires 'Data::Validate::URI';
|
requires 'Data::Validate::URI';
|
||||||
|
requires 'Term::ProgressBar';
|
||||||
|
|
||||||
feature 'ldap', 'LDAP authentication support' => sub {
|
feature 'ldap', 'LDAP authentication support' => sub {
|
||||||
requires 'Net::LDAP';
|
requires 'Net::LDAP';
|
||||||
|
|
|
@ -36,6 +36,21 @@ DISTRIBUTIONS
|
||||||
Canary::Stability 2012
|
Canary::Stability 2012
|
||||||
requirements:
|
requirements:
|
||||||
ExtUtils::MakeMaker 0
|
ExtUtils::MakeMaker 0
|
||||||
|
Capture-Tiny-0.48
|
||||||
|
pathname: D/DA/DAGOLDEN/Capture-Tiny-0.48.tar.gz
|
||||||
|
provides:
|
||||||
|
Capture::Tiny 0.48
|
||||||
|
requirements:
|
||||||
|
Carp 0
|
||||||
|
Exporter 0
|
||||||
|
ExtUtils::MakeMaker 6.17
|
||||||
|
File::Spec 0
|
||||||
|
File::Temp 0
|
||||||
|
IO::Handle 0
|
||||||
|
Scalar::Util 0
|
||||||
|
perl 5.006
|
||||||
|
strict 0
|
||||||
|
warnings 0
|
||||||
Class-Method-Modifiers-2.12
|
Class-Method-Modifiers-2.12
|
||||||
pathname: E/ET/ETHER/Class-Method-Modifiers-2.12.tar.gz
|
pathname: E/ET/ETHER/Class-Method-Modifiers-2.12.tar.gz
|
||||||
provides:
|
provides:
|
||||||
|
@ -49,6 +64,18 @@ DISTRIBUTIONS
|
||||||
perl 5.006
|
perl 5.006
|
||||||
strict 0
|
strict 0
|
||||||
warnings 0
|
warnings 0
|
||||||
|
Class-MethodMaker-2.24
|
||||||
|
pathname: S/SC/SCHWIGON/class-methodmaker/Class-MethodMaker-2.24.tar.gz
|
||||||
|
provides:
|
||||||
|
Class::MethodMaker 2.24
|
||||||
|
Class::MethodMaker::Constants undef
|
||||||
|
Class::MethodMaker::Engine 2.24
|
||||||
|
Class::MethodMaker::OptExt undef
|
||||||
|
Class::MethodMaker::V1Compat undef
|
||||||
|
Generate undef
|
||||||
|
requirements:
|
||||||
|
ExtUtils::MakeMaker 0
|
||||||
|
perl 5.006
|
||||||
Clone-Choose-0.010
|
Clone-Choose-0.010
|
||||||
pathname: H/HE/HERMES/Clone-Choose-0.010.tar.gz
|
pathname: H/HE/HERMES/Clone-Choose-0.010.tar.gz
|
||||||
provides:
|
provides:
|
||||||
|
@ -1408,6 +1435,46 @@ DISTRIBUTIONS
|
||||||
Text::Balanced 2
|
Text::Balanced 2
|
||||||
if 0
|
if 0
|
||||||
perl 5.005
|
perl 5.005
|
||||||
|
Term-ProgressBar-2.22
|
||||||
|
pathname: M/MA/MANWAR/Term-ProgressBar-2.22.tar.gz
|
||||||
|
provides:
|
||||||
|
Term::ProgressBar 2.22
|
||||||
|
Term::ProgressBar::IO 2.22
|
||||||
|
requirements:
|
||||||
|
Capture::Tiny 0.13
|
||||||
|
Carp 0
|
||||||
|
Class::MethodMaker 1.02
|
||||||
|
ExtUtils::MakeMaker 0
|
||||||
|
Fatal 0
|
||||||
|
File::Temp 0
|
||||||
|
POSIX 0
|
||||||
|
Term::ReadKey 2.14
|
||||||
|
Test::Exception 0.31
|
||||||
|
Test::More 0.80
|
||||||
|
Test::Warnings 0
|
||||||
|
perl 5.006
|
||||||
|
TermReadKey-2.37
|
||||||
|
pathname: J/JS/JSTOWE/TermReadKey-2.37.tar.gz
|
||||||
|
provides:
|
||||||
|
Term::ReadKey 2.37
|
||||||
|
requirements:
|
||||||
|
ExtUtils::MakeMaker 6.58
|
||||||
|
Test-Exception-0.43
|
||||||
|
pathname: E/EX/EXODIST/Test-Exception-0.43.tar.gz
|
||||||
|
provides:
|
||||||
|
Test::Exception 0.43
|
||||||
|
requirements:
|
||||||
|
Carp 0
|
||||||
|
Exporter 0
|
||||||
|
ExtUtils::MakeMaker 0
|
||||||
|
Sub::Uplevel 0.18
|
||||||
|
Test::Builder 0.7
|
||||||
|
Test::Builder::Tester 1.07
|
||||||
|
Test::Harness 2.03
|
||||||
|
base 0
|
||||||
|
perl 5.006001
|
||||||
|
strict 0
|
||||||
|
warnings 0
|
||||||
Test-Fatal-0.014
|
Test-Fatal-0.014
|
||||||
pathname: R/RJ/RJBS/Test-Fatal-0.014.tar.gz
|
pathname: R/RJ/RJBS/Test-Fatal-0.014.tar.gz
|
||||||
provides:
|
provides:
|
||||||
|
@ -1431,6 +1498,19 @@ DISTRIBUTIONS
|
||||||
Test::Builder 0.13
|
Test::Builder 0.13
|
||||||
Test::Builder::Tester 1.02
|
Test::Builder::Tester 1.02
|
||||||
perl 5.006
|
perl 5.006
|
||||||
|
Test-Warnings-0.026
|
||||||
|
pathname: E/ET/ETHER/Test-Warnings-0.026.tar.gz
|
||||||
|
provides:
|
||||||
|
Test::Warnings 0.026
|
||||||
|
requirements:
|
||||||
|
Carp 0
|
||||||
|
Exporter 0
|
||||||
|
ExtUtils::MakeMaker 0
|
||||||
|
Test::Builder 0
|
||||||
|
parent 0
|
||||||
|
perl 5.006
|
||||||
|
strict 0
|
||||||
|
warnings 0
|
||||||
Text-Soundex-3.05
|
Text-Soundex-3.05
|
||||||
pathname: R/RJ/RJBS/Text-Soundex-3.05.tar.gz
|
pathname: R/RJ/RJBS/Text-Soundex-3.05.tar.gz
|
||||||
provides:
|
provides:
|
||||||
|
|
|
@ -0,0 +1,116 @@
|
||||||
|
package Lufi::Command::sqliteToOtherDB;
|
||||||
|
use Mojo::Base 'Mojolicious::Command';
|
||||||
|
use Lufi::DB::File;
|
||||||
|
use Lufi::DB::Slice;
|
||||||
|
use Mojo::SQLite;
|
||||||
|
use FindBin qw($Bin);
|
||||||
|
use Term::ProgressBar;
|
||||||
|
|
||||||
|
has description => 'Migrate the records from a SQLite db to the currently configured database';
|
||||||
|
has usage => sub { shift->extract_usage };
|
||||||
|
|
||||||
|
sub run {
|
||||||
|
my $c = shift;
|
||||||
|
|
||||||
|
my $cfile = Mojo::File->new($Bin, '..' , 'lufi.conf');
|
||||||
|
if (defined $ENV{MOJO_CONFIG}) {
|
||||||
|
$cfile = Mojo::File->new($ENV{MOJO_CONFIG});
|
||||||
|
unless (-e $cfile->to_abs) {
|
||||||
|
$cfile = Mojo::File->new($Bin, '..', $ENV{MOJO_CONFIG});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
my $config = $c->app->plugin('Config', {
|
||||||
|
file => $cfile,
|
||||||
|
default => {
|
||||||
|
prefix => '/',
|
||||||
|
provisioning => 100,
|
||||||
|
provis_step => 5,
|
||||||
|
length => 10,
|
||||||
|
token_length => 32,
|
||||||
|
secrets => ['hfudsifdsih'],
|
||||||
|
default_delay => 0,
|
||||||
|
max_delay => 0,
|
||||||
|
mail => {
|
||||||
|
how => 'sendmail'
|
||||||
|
},
|
||||||
|
mail_sender => 'no-reply@lufi.io',
|
||||||
|
theme => 'default',
|
||||||
|
upload_dir => 'files',
|
||||||
|
session_duration => 3600,
|
||||||
|
allow_pwd_on_files => 0,
|
||||||
|
dbtype => 'sqlite',
|
||||||
|
db_path => 'lufi.db',
|
||||||
|
force_burn_after_reading => 0,
|
||||||
|
x_frame_options => 'DENY',
|
||||||
|
x_content_type_options => 'nosniff',
|
||||||
|
x_xss_protection => '1; mode=block',
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if ($config->{dbtype} eq 'sqlite') {
|
||||||
|
say 'Please configure `dbtype` to something else than `sqlite` to use this command.';
|
||||||
|
print $c->usage;
|
||||||
|
exit 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
my $sqlite = Mojo::SQLite->new('sqlite:'.$config->{db_path});
|
||||||
|
my $files = $sqlite->db->select('files', undef)->hashes;
|
||||||
|
my $slices = $sqlite->db->select('slices', undef)->hashes;
|
||||||
|
|
||||||
|
my $progress = Term::ProgressBar->new({count => $files->size + $slices->size});
|
||||||
|
|
||||||
|
$files->each(sub {
|
||||||
|
my ($file, $num) = @_;
|
||||||
|
|
||||||
|
$progress->update();
|
||||||
|
|
||||||
|
Lufi::DB::File->new(app => $c->app)
|
||||||
|
->short($file->{short})
|
||||||
|
->deleted($file->{deleted})
|
||||||
|
->mediatype($file->{mediatype})
|
||||||
|
->filename($file->{filename})
|
||||||
|
->filesize($file->{filesize})
|
||||||
|
->counter($file->{counter})
|
||||||
|
->delete_at_first_view($file->{delete_at_first_view})
|
||||||
|
->delete_at_day($file->{delete_at_day})
|
||||||
|
->created_at($file->{created_at})
|
||||||
|
->created_by($file->{created_by})
|
||||||
|
->last_access_at($file->{last_access_at})
|
||||||
|
->mod_token($file->{mod_token})
|
||||||
|
->nbslices($file->{nbslices})
|
||||||
|
->complete($file->{complete})
|
||||||
|
->passwd($file->{passwd})
|
||||||
|
->abuse($file->{abuse})
|
||||||
|
->write();
|
||||||
|
});
|
||||||
|
$slices->each(sub {
|
||||||
|
my ($slice, $num) = @_;
|
||||||
|
|
||||||
|
Lufi::DB::Slice->new(app => $c->app)
|
||||||
|
->short($slice->{short})
|
||||||
|
->j($slice->{j})
|
||||||
|
->path($slice->{path})
|
||||||
|
->write();
|
||||||
|
|
||||||
|
$progress->update();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
=encoding utf8
|
||||||
|
|
||||||
|
=head1 NAME
|
||||||
|
|
||||||
|
Lufi::Command::cron::sqliteToOtherDB Migrate the records from a SQLite db to the currently configured database
|
||||||
|
|
||||||
|
=head1 SYNOPSIS
|
||||||
|
|
||||||
|
Usage: script/lufi sqliteToOtherDB
|
||||||
|
|
||||||
|
This command needs you to:
|
||||||
|
- set `db_path` in your config file (otherwise, it will use the default path, `lufi.db` to migrate data from)
|
||||||
|
- set `dbtype` to an other database type in your config file
|
||||||
|
- configure the other database access in your config file
|
||||||
|
|
||||||
|
=cut
|
||||||
|
|
||||||
|
1;
|
Loading…
Reference in New Issue