🐛 — Avoid DB conflicts when provisioning

This commit is contained in:
Luc Didry
2021-06-20 07:59:26 +02:00
parent 614a561e00
commit d10ecc41fb
5 changed files with 17 additions and 10 deletions
+1
View File
@@ -32,6 +32,7 @@ feature 'postgresql', 'PostgreSQL support' => sub {
feature 'sqlite', 'SQLite support' => sub {
requires 'Mojo::SQLite', '>= 3.000';
requires 'Minion::Backend::SQLite', '>= 4.001';
requires 'DBD::SQLite', '>= 1.66';
};
feature 'minion', 'Minion support' => sub {
requires 'Minion';
+5 -5
View File
@@ -294,13 +294,13 @@ DISTRIBUTIONS
Test::More 0.88
Time::HiRes 0
version 0
DBD-SQLite-1.58
pathname: I/IS/ISHIGAKI/DBD-SQLite-1.58.tar.gz
DBD-SQLite-1.66
pathname: I/IS/ISHIGAKI/DBD-SQLite-1.66.tar.gz
provides:
DBD::SQLite 1.58
DBD::SQLite 1.66
DBD::SQLite::Constants undef
DBD::SQLite::VirtualTable 1.58
DBD::SQLite::VirtualTable::Cursor 1.58
DBD::SQLite::VirtualTable 1.66
DBD::SQLite::VirtualTable::Cursor 1.66
DBD::SQLite::VirtualTable::FileContent undef
DBD::SQLite::VirtualTable::FileContent::Cursor undef
DBD::SQLite::VirtualTable::PerlData undef
+5 -2
View File
@@ -78,12 +78,15 @@ sub select_empty {
}
sub write {
my $c = shift;
my $c = shift;
my $provisioning = shift;
if ($c->record) {
$c->app->pg->db->query('UPDATE lutim SET counter = ?, created_at = ?, created_by = ?, delete_at_day = ?, delete_at_first_view = ?, enabled = ?, filename = ?, footprint = ?, height = ?, last_access_at = ?, mediatype = ?, mod_token = ?, path = ?, short = ?, width = ?, iv = ? WHERE short = ?', $c->counter, $c->created_at, $c->created_by, $c->delete_at_day, $c->delete_at_first_view, $c->enabled, $c->filename, $c->footprint, $c->height, $c->last_access_at, $c->mediatype, $c->mod_token, $c->path, $c->short, $c->width, $c->iv, $c->short);
} else {
$c->app->pg->db->query('INSERT INTO lutim (counter, created_at, created_by, delete_at_day, delete_at_first_view, enabled, filename, footprint, height, last_access_at, mediatype, mod_token, path, short, width, iv) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $c->counter, $c->created_at, $c->created_by, $c->delete_at_day, $c->delete_at_first_view, $c->enabled, $c->filename, $c->footprint, $c->height, $c->last_access_at, $c->mediatype, $c->mod_token, $c->path, $c->short, $c->width, $c->iv);
my $query = 'INSERT INTO lutim (counter, created_at, created_by, delete_at_day, delete_at_first_view, enabled, filename, footprint, height, last_access_at, mediatype, mod_token, path, short, width, iv) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
$query .= ' ON CONFLICT DO NOTHING' if $provisioning;
$c->app->pg->db->query($query, $c->counter, $c->created_at, $c->created_by, $c->delete_at_day, $c->delete_at_first_view, $c->enabled, $c->filename, $c->footprint, $c->height, $c->last_access_at, $c->mediatype, $c->mod_token, $c->path, $c->short, $c->width, $c->iv);
$c->record(1);
}
+5 -2
View File
@@ -79,12 +79,15 @@ sub select_empty {
}
sub write {
my $c = shift;
my $c = shift;
my $provisioning = shift;
if ($c->record) {
$c->app->sqlite->db->query('UPDATE lutim SET counter = ?, created_at = ?, created_by = ?, delete_at_day = ?, delete_at_first_view = ?, enabled = ?, filename = ?, footprint = ?, height = ?, last_access_at = ?, mediatype = ?, mod_token = ?, path = ?, short = ?, width = ?, iv = ? WHERE short = ?', $c->counter, $c->created_at, $c->created_by, $c->delete_at_day, $c->delete_at_first_view, $c->enabled, $c->filename, $c->footprint, $c->height, $c->last_access_at, $c->mediatype, $c->mod_token, $c->path, $c->short, $c->width, $c->iv, $c->short);
} else {
$c->app->sqlite->db->query('INSERT INTO lutim (counter, created_at, created_by, delete_at_day, delete_at_first_view, enabled, filename, footprint, height, last_access_at, mediatype, mod_token, path, short, width, iv) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', $c->counter, $c->created_at, $c->created_by, $c->delete_at_day, $c->delete_at_first_view, $c->enabled, $c->filename, $c->footprint, $c->height, $c->last_access_at, $c->mediatype, $c->mod_token, $c->path, $c->short, $c->width, $c->iv);
my $query = 'INSERT INTO lutim (counter, created_at, created_by, delete_at_day, delete_at_first_view, enabled, filename, footprint, height, last_access_at, mediatype, mod_token, path, short, width, iv) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)';
$query .= ' ON CONFLICT DO NOTHING' if $provisioning;
$c->app->sqlite->db->query($query, $c->counter, $c->created_at, $c->created_by, $c->delete_at_day, $c->delete_at_first_view, $c->enabled, $c->filename, $c->footprint, $c->height, $c->last_access_at, $c->mediatype, $c->mod_token, $c->path, $c->short, $c->width, $c->iv);
$c->record(1);
}
+1 -1
View File
@@ -195,7 +195,7 @@ sub _provisioning {
->delete_at_first_view(0)
->delete_at_day(0)
->mod_token($c->shortener($c->app->config('token_length')))
->write;
->write('provisioning');
$img = Lutim::DB::Image->new(app => $c->app);
}