Skip to content

Instantly share code, notes, and snippets.

@theory
Last active January 20, 2016 00:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save theory/e7d432e69296e3672446 to your computer and use it in GitHub Desktop.
Save theory/e7d432e69296e3672446 to your computer and use it in GitHub Desktop.
#!/usr/bin/env perl
use v5.10;
use strict;
use warnings;
use URI;
=pod
=head1 Name
drop-sqitch-registry
=head1 Synopsis
project=batch
for target in `sqitch target`; do
drop-sqitch-registry.pl $project $target
done
=head1 Description
Use this script to drop the registry records from a Sqitch project database.
It will fail if other changes from other projects in the registry depend on
changes in the specified target.
=cut
my $project = shift or die "Usage: $0 PROJECT TARGET\n";
my $target = shift or die "Usage: $0 PROJECT TARGET\n";
my $uri;
if ($target =~ /^db:/) {
$uri = $target;
} else {
for my $line (`sqitch target show $target`) {
next unless $line =~ /URI:/;
($uri) = (split /\s+/ => $line)[2];
last;
}
die "No URI found for target $target\n" unless $uri;
}
$uri = URI->new($uri);
my @args = (
($uri->host ? (-h => $uri->host) : ()),
($uri->user ? (-U => $uri->user) : ()),
($uri->dbname ? (-d => $uri->dbname) : ()),
-c => qq{
BEGIN;
DELETE FROM sqitch.tags WHERE change_id IN (
SELECT change_id FROM sqitch.changes WHERE project = '$project'
);
DELETE FROM sqitch.dependencies WHERE change_id IN (
SELECT change_id FROM sqitch.changes WHERE project = '$project'
);
DELETE FROM sqitch.changes WHERE project = '$project';
DELETE FROM sqitch.changes WHERE project = '$project';
DELETE FROM sqitch.events WHERE project = '$project';
DELETE FROM sqitch.projects WHERE project = '$project';
COMMIT;
},
);
system('psql', @args) == 0 or die "psql @args failed: $?, $!\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment