Fix bug in argument order, strenghten argument parsing to avoid that.

Add a "meta" table that just contains a schema version and a hash.

So that some clients (e.g., portroach) can automatically figure out
whether a rebuild is required.
This commit is contained in:
espie 2019-03-15 11:29:53 +00:00
parent 37b8089d41
commit 9f70fcb4b8
4 changed files with 44 additions and 16 deletions

View File

@ -1,7 +1,7 @@
# $OpenBSD: Makefile,v 1.110 2019/03/11 13:29:21 espie Exp $ # $OpenBSD: Makefile,v 1.111 2019/03/15 11:29:53 espie Exp $
CATEGORIES = databases CATEGORIES = databases
V = 7.19 V = 7.20
DISTNAME = sqlports-$V DISTNAME = sqlports-$V
DISTFILES = DISTFILES =
COMMENT = sqlite database of ports COMMENT = sqlite database of ports
@ -23,14 +23,14 @@ RUN_DEPENDS-main = databases/sqlite3
SCRIPTS = print-ports-index show-reverse-deps SCRIPTS = print-ports-index show-reverse-deps
do-build: do-build:
@unset MAKEFLAGS; unset BUILD_ONCE; cd ${PORTSDIR} && PORTSDIR=${PORTSDIR} ${MAKE_ENV} perl ${FILESDIR}/mksqlitedb -v ${WRKBUILD}/${DBNAME} -p ${WRKBUILD}/ouch @unset MAKEFLAGS; unset BUILD_ONCE; cd ${PORTSDIR} && PORTSDIR=${PORTSDIR} ${MAKE_ENV} perl ${FILESDIR}/mksqlitedb -v -V $V -p ${WRKBUILD}/ouch ${WRKBUILD}/${DBNAME}
@if test -s ${WRKBUILD}/ouch; then \ @if test -s ${WRKBUILD}/ouch; then \
cat ${WRKBUILD}/ouch; \ cat ${WRKBUILD}/ouch; \
exit 1; \ exit 1; \
fi fi
alter-tables: alter-tables:
@unset MAKEFLAGS; unset BUILD_ONCE; cd ${PORTSDIR} && PORTSDIR=${PORTSDIR} ${MAKE_ENV} ${SUDO} -u ${BUILD_USER} perl ${FILESDIR}/rebuild_schema -v ${WRKBUILD}/${DBNAME} -p ${WRKBUILD}/ouch @unset MAKEFLAGS; unset BUILD_ONCE; cd ${PORTSDIR} && PORTSDIR=${PORTSDIR} ${MAKE_ENV} ${SUDO} -u ${BUILD_USER} perl ${FILESDIR}/rebuild_schema -v -V $V ${WRKBUILD/${DBNAME}
@${SUDO} -u ${BUILD_USER} ${MAKE} post-build @${SUDO} -u ${BUILD_USER} ${MAKE} post-build
post-build: post-build:

View File

@ -1,5 +1,5 @@
#! /usr/bin/perl #! /usr/bin/perl
# $OpenBSD: Inserter.pm,v 1.38 2019/01/22 16:55:22 espie Exp $ # $OpenBSD: Inserter.pm,v 1.39 2019/03/15 11:29:53 espie Exp $
# #
# Copyright (c) 2006-2010 Marc Espie <espie@openbsd.org> # Copyright (c) 2006-2010 Marc Espie <espie@openbsd.org>
# #
@ -68,6 +68,7 @@ sub create_tables
$v->sort; $v->sort;
$v->prepend(AnyVar->pathref); $v->prepend(AnyVar->pathref);
$self->create_meta;
$self->create_schema; $self->create_schema;
print '-'x50, "\n" if $self->{verbose}; print '-'x50, "\n" if $self->{verbose};
} }
@ -257,9 +258,15 @@ sub adjust
return $self->{adjust} //= $self->prepare("UPDATE _Paths set Canonical=? where Id=?"); return $self->{adjust} //= $self->prepare("UPDATE _Paths set Canonical=? where Id=?");
} }
sub create_meta
{
Sql::Create::Table->new("Meta")->add(
Sql::Column::Text->new("SchemaVersion"),
Sql::Column::Text->new("Hash"));
}
sub create_path_table sub create_path_table
{ {
my $self = shift;
my $t = "_Paths"; my $t = "_Paths";
my $v = "Paths"; my $v = "Paths";
Sql::Create::Table->new($t)->add( Sql::Create::Table->new($t)->add(

View File

@ -1,5 +1,5 @@
#! /usr/bin/perl #! /usr/bin/perl
# $OpenBSD: mksqlitedb,v 1.53 2019/01/08 19:42:45 espie Exp $ # $OpenBSD: mksqlitedb,v 1.54 2019/03/15 11:29:53 espie Exp $
# #
# Copyright (c) 2006-2010 Marc Espie <espie@openbsd.org> # Copyright (c) 2006-2010 Marc Espie <espie@openbsd.org>
# #
@ -96,16 +96,29 @@ sub handle_path
} }
package main; package main;
use Digest::SHA;
use MIME::Base64;
our ($opt_v, $opt_q, $opt_p); sub digest
{
my $filename = shift;
my $d = Digest::SHA->new(256);
$d->addfile($filename);
return encode_base64($d->digest, '');
}
our ($opt_v, $opt_q, $opt_p, $opt_V);
Trace->setup(\%SIG); Trace->setup(\%SIG);
getopts('vq:p:'); getopts('vq:p:V:');
my $dbname; my $dbname;
if (@ARGV > 0) { if (@ARGV == 1) {
$dbname = shift; $dbname = shift;
} else { } elsif (@ARGV == 0) {
$dbname = 'sqlports'; $dbname = 'sqlports';
} else {
exit 1;
} }
my $db = DBI->connect("dbi:SQLite:dbname=$dbname", '', '', {AutoCommit => 0}); my $db = DBI->connect("dbi:SQLite:dbname=$dbname", '', '', {AutoCommit => 0});
@ -131,6 +144,8 @@ for my $p (sort keys %{$walker->{equivs}}) {
$walker->inserter->add_path($p, $a); $walker->inserter->add_path($p, $a);
} }
$walker->inserter->commit_to_db;
$walker->inserter->insert("Meta", $opt_V, digest($dbname));
$walker->inserter->commit_to_db; $walker->inserter->commit_to_db;
while (my ($k, $v) = each %$Info::unknown) { while (my ($k, $v) = each %$Info::unknown) {

View File

@ -1,5 +1,5 @@
#! /usr/bin/perl #! /usr/bin/perl
# $OpenBSD: rebuild_schema,v 1.2 2019/01/08 19:42:45 espie Exp $ # $OpenBSD: rebuild_schema,v 1.3 2019/03/15 11:29:53 espie Exp $
# #
# Copyright (c) 2018 Marc Espie <espie@openbsd.org> # Copyright (c) 2018 Marc Espie <espie@openbsd.org>
# #
@ -35,15 +35,17 @@ use Trace;
package main; package main;
our ($opt_v, $opt_q, $opt_p); our ($opt_v, $opt_q, $opt_p, $opt_V);
Trace->setup(\%SIG); Trace->setup(\%SIG);
getopts('vq:p:'); getopts('vq:p:V:');
my $dbname; my $dbname;
if (@ARGV > 0) { if (@ARGV == 1) {
$dbname = shift; $dbname = shift;
} else { } elsif (@ARGV == 0) {
$dbname = 'sqlports'; $dbname = 'sqlports';
} else {
exit 1;
} }
my $db = DBI->connect("dbi:SQLite:dbname=$dbname", '', '', {AutoCommit => 0}); my $db = DBI->connect("dbi:SQLite:dbname=$dbname", '', '', {AutoCommit => 0});
@ -51,4 +53,8 @@ my $inserter = Inserter->new($db, 1000, $opt_v, 0);
$inserter->create_tables($Info::vars); $inserter->create_tables($Info::vars);
my $stmt = $db->prepare("UPDATE Meta set SchemaVersion=?");
$stmt->execute($opt_V);
$inserter->commit_to_db; $inserter->commit_to_db;