1
0
Fork 0
mirror of https://github.com/perlbot/perlbuut synced 2025-06-07 17:15:40 -04:00

working through more, need perltidy

This commit is contained in:
Ryan Voots 2020-09-06 20:46:51 -07:00
parent 1adff774d8
commit 6ade1a4b4c
2 changed files with 111 additions and 98 deletions

View file

@ -1,4 +1,9 @@
package Bot::BB3::Plugin::Factoids; package Bot::BB3::Plugin::Factoids;
use v5.30;
use experimental 'signatures';
use feature 'postderef', 'fc';
use DBI; use DBI;
use DBD::SQLite; use DBD::SQLite;
use DBD::SQLite::BundledExtensions; use DBD::SQLite::BundledExtensions;
@ -54,9 +59,7 @@ my %commandhash = (
$commands_re = qr/$commands_re/; $commands_re = qr/$commands_re/;
sub new { sub new($class) {
my( $class ) = @_;
my $self = bless {}, $class; my $self = bless {}, $class;
$self->{name} = 'factoids'; # Shouldn't matter since we aren't a command $self->{name} = 'factoids'; # Shouldn't matter since we aren't a command
$self->{opts} = { $self->{opts} = {
@ -68,9 +71,7 @@ sub new {
return $self; return $self;
} }
sub dbh { sub dbh($self) {
my( $self ) = @_;
if( $self->{dbh} and $self->{dbh}->ping ) { if( $self->{dbh} and $self->{dbh}->ping ) {
return $self->{dbh}; return $self->{dbh};
} }
@ -87,8 +88,8 @@ sub dbh {
return $dbh; return $dbh;
} }
sub get_conf_for_channel { sub get_conf_for_channel($self, $pm, $server, $channel) {
my ($self, $pm, $server, $channel) = @_; # TODO this needs to use the tables now
my $gc = sub {$pm->plugin_conf($_[0], $server, $channel)}; my $gc = sub {$pm->plugin_conf($_[0], $server, $channel)};
# Load factoids if it exists, otherwise grab the old nfacts setup # Load factoids if it exists, otherwise grab the old nfacts setup
@ -96,7 +97,9 @@ sub get_conf_for_channel {
return $conf; return $conf;
} }
sub get_namespaced_factoid { # This must go away instead
# TODO
sub __get_namespaced_factoid {
my ($self, $pm, $body, $said, $forcechan, $forceserver) = @_; my ($self, $pm, $body, $said, $forcechan, $forceserver) = @_;
my $command; my $command;
@ -129,17 +132,18 @@ sub get_namespaced_factoid {
return ($realserver, $realchannel, $body); return ($realserver, $realchannel, $body);
} }
sub namespace_filter { # TODO remove this
sub __namespace_filter {
my ($self, $body, $enabled) = @_; my ($self, $body, $enabled) = @_;
return $body =~ s|$fsep[^$fsep]*?$fsep[^$fsep]*?$fsep(\S+)|$1|rg if $enabled; return $body =~ s|$fsep[^$fsep]*?$fsep[^$fsep]*?$fsep(\S+)|$1|rg if $enabled;
$body; $body;
} }
# TODO update this to use the new table layout once it's ready
sub postload { sub postload {
my( $self, $pm ) = @_; my( $self, $pm ) = @_;
# my $sql = "CREATE TABLE factoid ( # my $sql = "CREATE TABLE factoid (
# factoid_id INTEGER PRIMARY KEY AUTOINCREMENT, # factoid_id INTEGER PRIMARY KEY AUTOINCREMENT,
# original_subject VARCHAR(100), # original_subject VARCHAR(100),
@ -169,8 +173,7 @@ sub postload {
# if it's a retrieve command such as "foo" or if it's a retrieve sub- # if it's a retrieve command such as "foo" or if it's a retrieve sub-
# command such as "forget foo" # command such as "forget foo"
# Need to add "what is foo?" support... # Need to add "what is foo?" support...
sub command { sub command($self, $_said, $pm) {
my( $self, $_said, $pm ) = @_;
my $said = +{$_said->%*}; my $said = +{$_said->%*};
my $conf = $self->get_conf_for_channel($pm, $said->{server}, $said->{channel}); my $conf = $self->get_conf_for_channel($pm, $said->{server}, $said->{channel});
@ -183,6 +186,8 @@ sub command {
my $response; #namespaced factoids have no fallback my $response; #namespaced factoids have no fallback
my ($realchannel, $realserver); my ($realchannel, $realserver);
# I want to rework this TODO
if ($conf->{namespaced} || $said->{channel} eq '*irc_msg') { if ($conf->{namespaced} || $said->{channel} eq '*irc_msg') {
# Parse body here # Parse body here
my $body = $said->{body}; my $body = $said->{body};
@ -227,9 +232,7 @@ sub command {
return ($handled, $fact_out); return ($handled, $fact_out);
} }
sub sub_command { sub sub_command ($self, $said, $pm, $realchannel, $realserver) {
my( $self, $said, $pm, $realchannel, $realserver ) = @_;
return unless $said->{body} =~ /\S/; #Try to prevent "false positives" return unless $said->{body} =~ /\S/; #Try to prevent "false positives"
my $call_only = $said->{command_match} eq "call"; my $call_only = $said->{command_match} eq "call";
@ -277,11 +280,9 @@ sub sub_command {
} }
# Handler code stolen from the old nfacts plugin # Handler code stolen from the old nfacts plugin
sub handle { sub handle($self, $said, $pm) {
my ($self, $said, $pm) = @_;
my $conf = $self->get_conf_for_channel($pm, $said->{server}, $said->{channel}); my $conf = $self->get_conf_for_channel($pm, $said->{server}, $said->{channel});
$said->{body} =~ s/^\s*(what|who|where|how|when|why)\s+($COPULA_RE)\s+(?<fact>.*?)\??\s*$/$+{fact}/i; $said->{body} =~ s/^\s*(what|who|where|how|when|why)\s+($COPULA_RE)\s+(?<fact>.*?)\??\s*$/$+{fact}/i;
my $prefix = $conf->{prefix_command}; my $prefix = $conf->{prefix_command};
@ -319,20 +320,18 @@ sub handle {
} }
sub _clean_subject { sub _clean_subject($subject) {
my( $subject ) = @_;
$subject =~ s/^\s+//; $subject =~ s/^\s+//;
$subject =~ s/\s+$//; $subject =~ s/\s+$//;
$subject =~ s/\s+/ /g; $subject =~ s/\s+/ /g;
# $subject =~ s/[^\w\s]//g; #comment out to fix punct in factoids # $subject =~ s/[^\w\s]//g; #comment out to fix punct in factoids
$subject = lc $subject; $subject = lc fc $subject;
return $subject; return $subject;
} }
sub _clean_subject_func { # for parametrized macros # TODO document this better
my($subject, $variant) = @_; sub _clean_subject_func($subject, $variant) { # for parametrized macros
my( $key, $arg ); my( $key, $arg );
if ($variant) { if ($variant) {
@ -345,13 +344,18 @@ sub _clean_subject_func { # for parametrized macros
( $key, $arg ) = ( $1, $2 ); ( $key, $arg ) = ( $1, $2 );
} }
#$key =~ s/[^\w\s]//g;
return $key, $arg; return $key, $arg;
} }
sub store_factoid { sub store_factoid($self, $said) {
my( $self, $said) =@_; my( $self, $said) =@_;
# alias namespace is the current alias we assign factoids to
# server and namespace is the server and channel we're looking up for
my ($aliasserver, $aliasnamespace) = $self->get_alias_namespace($said);
my ($server, $namespace) = $self->get_namespace($said);
my ($author, $body ) = ($said->{name}, $said->{body}); my ($author, $body ) = ($said->{name}, $said->{body});
return unless $body =~ /^(?:no[, ])?\s*(.+?)\s+($COPULA_RE)\s+(.+)$/s; return unless $body =~ /^(?:no[, ])?\s*(.+?)\s+($COPULA_RE)\s+(.+)$/s;
@ -363,19 +367,19 @@ sub store_factoid {
if( $subject =~ s/^\s*\@?macro\b\s*// ) { $compose_macro = 1; } if( $subject =~ s/^\s*\@?macro\b\s*// ) { $compose_macro = 1; }
elsif( $subject =~ s/^\s*\@?func\b\s*// ) { $compose_macro = 2; } elsif( $subject =~ s/^\s*\@?func\b\s*// ) { $compose_macro = 2; }
elsif( $predicate =~ s/^\s*also\s+// ) { elsif( $predicate =~ s/^\s*also\s+// ) {
my $fact = $self->_db_get_fact( _clean_subject( $subject ), $author ); my $fact = $self->_db_get_fact( _clean_subject( $subject ), $author, $server, $namespace );
$predicate = $fact->{predicate} . " | " . $predicate; $predicate = $fact->{predicate} . " | " . $predicate;
} }
return unless return unless
$self->_insert_factoid( $author, $subject, $copula, $predicate, $compose_macro, $self->_db_get_protect($subject) ); $self->_insert_factoid( $author, $subject, $copula, $predicate, $compose_macro, $self->_db_get_protect($subject, $server, $namespace), $aliasserver, $aliasnamespace );
return( $subject, $copula, $predicate ); return( $subject, $copula, $predicate );
} }
sub _insert_factoid { sub _insert_factoid ($self, $author, $subject, $copula, $predicate, $compose_macro, $protected, $server, $namespace) {
my( $self, $author, $subject, $copula, $predicate, $compose_macro, $protected, $realchannel, $realserver ) = @_; my= @_;
my $dbh = $self->dbh; my $dbh = $self->dbh;
warn "Attempting to insert factoid: type $compose_macro"; warn "Attempting to insert factoid: type $compose_macro";
@ -406,26 +410,27 @@ sub _insert_factoid {
Metaphone($key), Metaphone($key),
$compose_macro || 0, $compose_macro || 0,
$protected || 0, $protected || 0,
$realchannel, $namespace,
$realserver $server
); );
return 1; return 1;
} }
sub get_fact_protect { sub get_fact_protect($self, $subject, $name, $said) {
my( $self, $subject, $name, $said ) = @_; my ($aliasserver, $aliasnamespace) = $self->get_alias_namespace($said);
my ($server, $namespace) = $self->get_namespace($said);
warn "===TRYING TO PROTECT [$subject] [$name]\n";
warn "===TRYING TO PROTECT [$subject] [$name]\n";
#XXX check permissions here #XXX check permissions here
return "Insufficient permissions for protecting factoid [$subject]" if (!$self->_db_check_perm($subject,$said)); return "Insufficient permissions for protecting factoid [$subject]" if (!$self->_db_check_perm($subject,$said));
my $fact = $self->_db_get_fact( _clean_subject( $subject ), $name ); my $fact = $self->_db_get_fact( _clean_subject( $subject ), $name, $server, $namespace );
if (defined($fact->{predicate})) if (defined($fact->{predicate}))
{ {
$self->_insert_factoid( $name, $subject, $fact->{copula}, $fact->{predicate}, $fact->{compose_macro}, 1 ); $self->_insert_factoid( $name, $subject, $fact->{copula}, $fact->{predicate}, $fact->{compose_macro}, 1, $aliasserver, $aliasnamespace );
return "Protected [$subject]"; return "Protected [$subject]";
} }
@ -435,19 +440,20 @@ sub get_fact_protect {
} }
} }
sub get_fact_unprotect { sub get_fact_unprotect($self, $subject, $name, $said) {
my( $self, $subject, $name, $said ) = @_; my ($aliasserver, $aliasnamespace) = $self->get_alias_namespace($said);
my ($server, $namespace) = $self->get_namespace($said);
warn "===TRYING TO PROTECT [$subject] [$name]\n";
warn "===TRYING TO PROTECT [$subject] [$name]\n";
#XXX check permissions here #XXX check permissions here
return "Insufficient permissions for unprotecting factoid [$subject]" if (!$self->_db_check_perm($subject,$said)); return "Insufficient permissions for unprotecting factoid [$subject]" if (!$self->_db_check_perm($subject,$said));
my $fact = $self->_db_get_fact( _clean_subject( $subject ), $name ); my $fact = $self->_db_get_fact( _clean_subject( $subject ), $name, $server, $namespace );
if (defined($fact->{predicate})) if (defined($fact->{predicate}))
{ {
$self->_insert_factoid( $name, $subject, $fact->{copula}, $fact->{predicate}, $fact->{compose_macro}, 0 ); $self->_insert_factoid( $name, $subject, $fact->{copula}, $fact->{predicate}, $fact->{compose_macro}, 0, $aliasserver, $aliasnamespace );
return "Unprotected [$subject]"; return "Unprotected [$subject]";
} }
@ -457,30 +463,34 @@ sub get_fact_unprotect {
} }
} }
sub get_fact_forget { sub get_fact_forget($self, $subject, $name, $said) {
my( $self, $subject, $name, $said ) = @_; my ($aliasserver, $aliasnamespace) = $self->get_alias_namespace($said);
my ($server, $namespace) = $self->get_namespace($said);
warn "===TRYING TO FORGET [$subject] [$name]\n";
warn "===TRYING TO FORGET [$subject] [$name]\n";
#XXX check permissions here #XXX check permissions here
return "Insufficient permissions for forgetting protected factoid [$subject]" if (!$self->_db_check_perm($subject,$said)); return "Insufficient permissions for forgetting protected factoid [$subject]" if (!$self->_db_check_perm($subject,$said));
$self->_insert_factoid( $name, $subject, "is", " ", 0, $self->_db_get_protect($subject) ); $self->_insert_factoid( $name, $subject, "is", " ", 0, $self->_db_get_protect($subject, $server, $namespace), $aliasserver, $aliasnamespace );
return "Forgot $subject"; return "Forgot $subject";
} }
sub _fact_literal_format { sub _fact_literal_format($r) {
my($r) = @_; # TODO make this express the parent namespace if present
($r->{protected}?"P:" : "" ). # <server:namespace>
($r->{protected}?"P:" : "" ).
("","macro ","func ")[$r->{compose_macro}] . ("","macro ","func ")[$r->{compose_macro}] .
"$r->{subject} $r->{copula} $r->{predicate}"; "$r->{subject} $r->{copula} $r->{predicate}";
} }
sub get_fact_revisions { sub get_fact_revisions($self, $subject, $name) {
my( $self, $subject, $name ) = @_;
my $dbh = $self->dbh; my $dbh = $self->dbh;
my ($server, $namespace) = $self->get_namespace($said);
# TODO this query needs to be rewritten
my $revisions = $dbh->selectall_arrayref( my $revisions = $dbh->selectall_arrayref(
"SELECT factoid_id, subject, copula, predicate, author, compose_macro, protected "SELECT factoid_id, subject, copula, predicate, author, compose_macro, protected
FROM factoid FROM factoid
@ -498,24 +508,19 @@ sub get_fact_revisions {
return $ret_string; return $ret_string;
} }
sub get_fact_literal { sub get_fact_literal($self, $subject, $name) {
my( $self, $subject, $name ) = @_;
my ($server, $namespace) = $self->get_namespace($said);
my $fact = $self->_db_get_fact( _clean_subject( $subject ), $name ); my $fact = $self->_db_get_fact( _clean_subject( $subject ), $name, $server, $namespace );
return _fact_literal_format($fact); return _fact_literal_format($fact);
} }
sub _fact_substitute sub _fact_substitute($self, $pred, $match, $subst, $flags) {
{ if ($flags =~ /g/) {
my ($self, $pred, $match, $subst, $flags) = @_;
if ($flags =~ /g/)
{
my $regex = $flags=~/i/ ? qr/(?i:$match)/i : qr/$match/; my $regex = $flags=~/i/ ? qr/(?i:$match)/i : qr/$match/;
while ($pred =~ /$regex/g) while ($pred =~ /$regex/g) {
{
my $matchedstring = substr($pred, $-[0], $+[0] - $-[0]); my $matchedstring = substr($pred, $-[0], $+[0] - $-[0]);
my ($matchstart, $matchend) = ($-[0], $+[0]); my ($matchstart, $matchend) = ($-[0], $+[0]);
my @caps = map {substr($pred, $-[$_], $+[$_] - $-[$_])} 1..$#+; my @caps = map {substr($pred, $-[$_], $+[$_] - $-[$_])} 1..$#+;
@ -528,13 +533,10 @@ sub _fact_substitute
} }
return $pred; return $pred;
} } else {
else
{
my $regex = $flags=~/i/ ? qr/(?i:$match)/i : qr/$match/; my $regex = $flags=~/i/ ? qr/(?i:$match)/i : qr/$match/;
if ($pred =~ /$regex/) if ($pred =~ /$regex/) {
{
my @caps = map {substr($pred, $-[$_], $+[$_] - $-[$_])} 1..$#+; my @caps = map {substr($pred, $-[$_], $+[$_] - $-[$_])} 1..$#+;
my $realsubst = $subst; my $realsubst = $subst;
$realsubst =~ s/(?<!\\)\$(?:\{(\d+)\}|(\d+))/$caps[$1-1]/eg; $realsubst =~ s/(?<!\\)\$(?:\{(\d+)\}|(\d+))/$caps[$1-1]/eg;
@ -547,8 +549,10 @@ sub _fact_substitute
} }
} }
sub get_fact_substitute { sub get_fact_substitute($self, $subject, $name, $said) {
my( $self, $subject, $name, $said, $realchannel, $realserver ) = @_;
my ($aliasserver, $aliasnamespace) = $self->get_alias_namespace($said);
my ($server, $namespace) = $self->get_namespace($said);
if ( if (
($said->{body} =~ m{^(?:\s*substitute)?\s*(.*?)\s*=~\s*s /([^/]+ ) /([^/]* )/([gi]*)\s*$}ix) || ($said->{body} =~ m{^(?:\s*substitute)?\s*(.*?)\s*=~\s*s /([^/]+ ) /([^/]* )/([gi]*)\s*$}ix) ||
@ -561,7 +565,7 @@ sub get_fact_substitute {
my ($subject, $match, $subst, $flags) = ($1, $2, $3, $4); my ($subject, $match, $subst, $flags) = ($1, $2, $3, $4);
# TODO does this need to be done via the ->get_fact() instead now? # TODO does this need to be done via the ->get_fact() instead now?
my $fact = $self->_db_get_fact( _clean_subject( $subject ), $name, $realchannel, $realserver ); my $fact = $self->_db_get_fact( _clean_subject( $subject ), $name, $server, $namespace );
if ($fact && $fact->{predicate} =~ /\S/) if ($fact && $fact->{predicate} =~ /\S/)
{ #we've got a fact to operate on { #we've got a fact to operate on
@ -578,7 +582,9 @@ sub get_fact_substitute {
# $body =~ s/^\s*learn\s+//; # $body =~ s/^\s*learn\s+//;
# my( $subject, $predicate ) = split /\s+as\s+/, $body, 2; # my( $subject, $predicate ) = split /\s+as\s+/, $body, 2;
my $ret = $self->get_fact_learn("learn $subject as $result", $name, $said, $subject, $result, $realchannel, $realserver); # TODO why is this calling there?
# let this fail for now
my $ret = $self->get_fact_learn("learn $subject as $result", $name, $said, $subject, $result);
return $ret; return $ret;
} }
@ -594,9 +600,11 @@ sub get_fact_substitute {
} }
} }
sub get_fact_revert { sub get_fact_revert($self, $subject, $name, $said) {
my( $self, $subject, $name, $said ) = @_;
my $dbh = $self->dbh; my $dbh = $self->dbh;
my ($aliasserver, $aliasnamespace) = $self->get_alias_namespace($said);
my ($server, $namespace) = $self->get_namespace($said);
#XXX check permissions here #XXX check permissions here
return "Insufficient permissions for reverting protected factoid [$subject]" if (!$self->_db_check_perm($subject,$said)); return "Insufficient permissions for reverting protected factoid [$subject]" if (!$self->_db_check_perm($subject,$said));
@ -613,20 +621,22 @@ sub get_fact_revert {
$rev_id $rev_id
); );
my $protect = $self->_db_get_protect($fact_rev->{subject}); my $protect = $self->_db_get_protect($fact_rev->{subject}, $server, $namespace);
return "Bad revision id" unless $fact_rev and $fact_rev->{subject}; # Make sure it's valid.. return "Bad revision id" unless $fact_rev and $fact_rev->{subject}; # Make sure it's valid..
# subject, copula, predicate # subject, copula, predicate
$self->_insert_factoid( $name, @$fact_rev{qw"subject copula predicate compose_macro"}, $protect); $self->_insert_factoid( $name, @$fact_rev{qw"subject copula predicate compose_macro"}, $protect, $aliasserver, $aliasnamespace);
return "Reverted $fact_rev->{subject} to revision $rev_id"; return "Reverted $fact_rev->{subject} to revision $rev_id";
} }
sub get_fact_learn { sub get_fact_learn($self, $body, $name, $said, $subject, $predicate) {
my( $self, $body, $name, $said, $subject, $predicate, $realchannel, $realserver ) = @_;
my ($aliasserver, $aliasnamespace) = $self->get_alias_namespace($said);
my ($server, $namespace) = $self->get_namespace($said);
return if ($said->{nolearn}); return if ($said->{nolearn});
$body =~ s/^\s*learn\s+//; $body =~ s/^\s*learn\s+//;
($subject, $predicate ) = split /\s+as\s+/, $body, 2 unless ($subject && $predicate); ($subject, $predicate ) = split /\s+as\s+/, $body, 2 unless ($subject && $predicate);
@ -635,17 +645,20 @@ sub get_fact_learn {
return "Insufficient permissions for changing protected factoid [$subject]" if (!$self->_db_check_perm($subject,$said)); return "Insufficient permissions for changing protected factoid [$subject]" if (!$self->_db_check_perm($subject,$said));
#my @ret = $self->store_factoid( $name, $said->{body} ); #my @ret = $self->store_factoid( $name, $said->{body} );
$self->_insert_factoid( $name, $subject, 'is', $predicate, 0 , $self->_db_get_protect($subject), $realchannel, $realserver); $self->_insert_factoid( $name, $subject, 'is', $predicate, 0 , $self->_db_get_protect($subject), $aliasserver, $aliasnamespace);
return "Stored $subject as $predicate"; return "Stored $subject as $predicate";
} }
sub get_fact_search { sub get_fact_search($self, $body, $name) {
my( $self, $body, $name ) = @_; # TODO replace this with FTS
#my $namespace = $self my ($aliasserver, $aliasnamespace) = $self->get_alias_namespace($said);
my ($server, $namespace) = $self->get_namespace($said);
$body =~ s/^\s*for\s*//; #remove the for from searches
$body =~ s/^\s*for\s*//; #remove the for from searches # TODO queries need the CTE
my $results; my $results;
@ -691,15 +704,14 @@ sub get_fact_search {
} }
sub get_fact { sub get_fact($self, $pm, $said, $subject, $name, $call_only) {
my( $self, $pm, $said, $subject, $name, $call_only ) = @_;
return $self->basic_get_fact( $pm, $said, $subject, $name, $call_only ); return $self->basic_get_fact( $pm, $said, $subject, $name, $call_only );
} }
sub _db_check_perm { sub _db_check_perm($self, $subj, $said) {
my ($self, $subj, $said) = @_; my ($server, $namespace) = $self->get_namespace($said);
my $isprot = $self->_db_get_protect($subj);
my $isprot = $self->_db_get_protect($subj, $server, $namespace);
warn "Checking permissions of [$subj] for [$said->{name}]"; warn "Checking permissions of [$subj] for [$said->{name}]";
warn Dumper($said); warn Dumper($said);
@ -720,8 +732,8 @@ sub _db_check_perm {
} }
#get the status of the protection bit #get the status of the protection bit
sub _db_get_protect { sub _db_get_protect($self, $subj, $server, $namespace) {
my( $self, $subj ) = @_; # TODO switch to new CTE query
$subj = _clean_subject($subj,1); $subj = _clean_subject($subj,1);
@ -740,8 +752,7 @@ sub _db_get_protect {
} }
sub _db_get_fact { sub _db_get_fact($self, $subj, $func, $namespace, $server) {
my( $self, $subj, $name, $func, $realchannel, $realserver ) = @_;
# TODO write the recursive CTE for this # TODO write the recursive CTE for this

View file

@ -9,11 +9,13 @@ ALTER TABLE public.factoid ALTER COLUMN author TYPE text;
ALTER TABLE public.factoid ADD COLUMN deleted boolean DEFAULT false; ALTER TABLE public.factoid ADD COLUMN deleted boolean DEFAULT false;
ALTER TABLE public.factoid ADD COLUMN namespace text; ALTER TABLE public.factoid ADD COLUMN namespace text;
ALTER TABLE public.factoid ADD COLUMN server text; ALTER TABLE public.factoid ADD COLUMN server text;
ALTER TABLE public.factoid ADD COLUMN last_rendered text;
UPDATE public.factoid SET namespace=split_part(original_subject, E'\034', 3), server=split_part(original_subject, E'\034', 2); UPDATE public.factoid SET namespace=split_part(original_subject, E'\034', 3), server=split_part(original_subject, E'\034', 2);
UPDATE public.factoid SET namespace=NULL WHERE namespace = ''; UPDATE public.factoid SET namespace=NULL WHERE namespace = '';
UPDATE public.factoid SET server=NULL WHERE server = ''; UPDATE public.factoid SET server=NULL WHERE server = '';
UPDATE public.factoid SET original_subject=split_part(original_subject, E'\034', 4), subject=split_part(subject, E'\034', 4) WHERE namespace IS NOT NULL and server IS NOT NULL; UPDATE public.factoid SET original_subject=split_part(original_subject, E'\034', 4), subject=split_part(subject, E'\034', 4) WHERE namespace IS NOT NULL and server IS NOT NULL;
UPDATE public.factoid SET last_rendered = predicate; -- just copy macros as the last rendered, keeps old behavior until i code up the storage
DROP TABLE IF EXISTS public.factoid_namespace_config; DROP TABLE IF EXISTS public.factoid_namespace_config;
DROP TABLE IF EXISTS public.factoid_config; DROP TABLE IF EXISTS public.factoid_config;