[dw-free] remove legacy database tables
[commit: http://hg.dwscoalition.org/dw-free/rev/4d8bd333d94e]
http://bugs.dwscoalition.org/show_bug.cgi?id=1710
Remove s2source and s2stylelayers (global tables; been replaced by clustered
tables).
Patch by
kareila.
Files modified:
http://bugs.dwscoalition.org/show_bug.cgi?id=1710
Remove s2source and s2stylelayers (global tables; been replaced by clustered
tables).
Patch by
Files modified:
- bin/upgrading/s2style-wizard-update.pl
- bin/upgrading/update-db-general.pl
- cgi-bin/LJ/S2.pm
--------------------------------------------------------------------------------
diff -r b4d932a44be9 -r 4d8bd333d94e bin/upgrading/s2style-wizard-update.pl
--- a/bin/upgrading/s2style-wizard-update.pl Sun Sep 20 09:07:57 2009 +0000
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,73 +0,0 @@
-#!/usr/bin/perl
-
-use strict;
-$| = 1;
-
-require "$ENV{'LJHOME'}/cgi-bin/ljlib.pl";
-
-my $sysid = LJ::get_userid("system");
-die "Couldn't find system userid"
- unless $sysid;
-
-my $dbh = LJ::get_db_writer();
-die "Could not connect to global master"
- unless $dbh;
-
-
-# find info on styles based on public layouts
-
-# need to select from:
-# s2styles - get style name
-# s2stylelayers - get layout s2lid
-# s2layers - get userid of layer
-# s2info - get redist_uniq
-
-{
- print "Converting styles based on public layouts...";
-
- my $sth = $dbh->prepare("SELECT s.styleid, i.value " .
- "FROM s2styles s, s2stylelayers sl, s2layers l, s2info i " .
- "WHERE s.styleid=sl.styleid AND l.s2lid=sl.s2lid AND i.s2lid=l.s2lid " .
- "AND l.userid=? AND l.type='layout' AND s.name='wizard' " .
- "AND i.infokey='redist_uniq'");
- $sth->execute($sysid);
- my $ct = 0;
- while (my ($styleid, $redist_uniq) = $sth->fetchrow_array) {
-
- my $layout = (split("/", $redist_uniq))[0];
- $dbh->do("UPDATE s2styles SET name=? WHERE styleid=?",
- undef, "wizard-$layout", $styleid);
- $ct++;
- print "." if $ct % 1000 == 0;
- }
-
- print " $ct done.\n";
-}
-
-
-# find info on styles based on user layouts
-
-# need to select from:
-# s2styles - get style name
-# s2stylelayers - get layout s2lid
-# s2layers - get userid of layer
-
-{
- print "Converting styles based on user layouts...";
-
- my $sth = $dbh->prepare("SELECT s.styleid, l.s2lid " .
- "FROM s2styles s, s2stylelayers sl, s2layers l " .
- "WHERE s.styleid=sl.styleid AND l.s2lid=sl.s2lid " .
- "AND l.userid<>? AND l.type='layout' AND s.name='wizard'");
- $sth->execute($sysid);
- my $ct = 0;
- while (my ($styleid, $s2lid) = $sth->fetchrow_array) {
-
- $dbh->do("UPDATE s2styles SET name=? WHERE styleid=?",
- undef, "wizard-$s2lid", $styleid);
- $ct++;
- print "." if $ct % 1000 == 0;
- }
-
- print " $ct done.\n";
-}
diff -r b4d932a44be9 -r 4d8bd333d94e bin/upgrading/update-db-general.pl
--- a/bin/upgrading/update-db-general.pl Sun Sep 20 09:07:57 2009 +0000
+++ b/bin/upgrading/update-db-general.pl Sun Sep 20 09:15:19 2009 +0000
@@ -890,6 +890,8 @@ register_tabledrop("portal_typemap");
register_tabledrop("portal_typemap");
register_tabledrop("memkeyword");
register_tabledrop("memorable");
+register_tabledrop("s2source");
+register_tabledrop("s2stylelayers");
register_tablecreate("infohistory", <<'EOC');
CREATE TABLE infohistory (
@@ -1045,16 +1047,6 @@ CREATE TABLE s2info (
)
EOC
-# TODO: Move anything left here to s2source_inno for sites migrating from LJ
-# to DW, then nuke table. New sites should have nothing here.
-register_tablecreate("s2source", <<'EOC'); # global
-CREATE TABLE s2source (
- s2lid INT UNSIGNED NOT NULL,
- PRIMARY KEY (s2lid),
- s2code MEDIUMBLOB
-)
-EOC
-
register_tablecreate("s2source_inno", <<'EOC'); # global
CREATE TABLE s2source_inno (
s2lid INT UNSIGNED NOT NULL,
@@ -1104,15 +1096,6 @@ CREATE TABLE s2styles (
modtime INT UNSIGNED NOT NULL,
INDEX (userid)
-)
-EOC
-
-register_tablecreate("s2stylelayers", <<'EOC'); # global
-CREATE TABLE s2stylelayers (
- styleid INT UNSIGNED NOT NULL,
- type ENUM('core','i18nc','layout','theme','i18n','user') NOT NULL,
- UNIQUE (styleid, type),
- s2lid INT UNSIGNED NOT NULL
)
EOC
@@ -3239,15 +3222,6 @@ register_alter(sub {
set_dbnote("privcode_all_to_*", 1);
}
- # convert 'wizard' s2 styles to 'wizard-uniq'
- if (table_relevant("s2styles") && !check_dbnote("s2style-wizard-update")) {
-
- # set_dbnote will return true if $opt_sql is set and it sets
- # the note successfully. only then do we run the wizard updater
- set_dbnote("s2style-wizard-update", 1) &&
- system("$ENV{'LJHOME'}/bin/upgrading/s2style-wizard-update.pl");
- }
-
# this never ended up being useful, and just freaked people out unnecessarily.
if (column_type("user", "track")) {
do_alter("user", "ALTER TABLE user DROP track");
diff -r b4d932a44be9 -r 4d8bd333d94e cgi-bin/LJ/S2.pm
--- a/cgi-bin/LJ/S2.pm Sun Sep 20 09:07:57 2009 +0000
+++ b/cgi-bin/LJ/S2.pm Sun Sep 20 09:15:19 2009 +0000
@@ -867,59 +867,15 @@ sub cleanup_layers {
S2::unregister_layer($_) foreach grep { ! $pub->{$_} } @unload;
}
-sub clone_layer
-{
- die "LJ::S2::clone_layer() has not been ported to use s2compiled2, but this function is not currently in use anywhere; if you use this function, please update it to use s2compiled2.\n";
-
- my $id = shift;
- return 0 unless $id;
-
- my $dbh = LJ::get_db_writer();
- my $r;
-
- $r = $dbh->selectrow_hashref("SELECT * FROM s2layers WHERE s2lid=?", undef, $id);
- return 0 unless $r;
- $dbh->do("INSERT INTO s2layers (b2lid, userid, type) VALUES (?,?,?)",
- undef, $r->{'b2lid'}, $r->{'userid'}, $r->{'type'});
- my $newid = $dbh->{'mysql_insertid'};
- return 0 unless $newid;
-
- foreach my $t (qw(s2compiled s2info s2source)) {
- if ($t eq "s2source") {
- $r = LJ::S2::load_layer_source_row($id);
- } else {
- $r = $dbh->selectrow_hashref("SELECT * FROM $t WHERE s2lid=?", undef, $id);
- }
- next unless $r;
- $r->{'s2lid'} = $newid;
-
- # kinda hacky: we have to update the layer id
- if ($t eq "s2compiled") {
- $r->{'compdata'} =~ s/\$_LID = (\d+)/\$_LID = $newid/;
- }
-
- $dbh->do("INSERT INTO $t (" . join(',', keys %$r) . ") VALUES (".
- join(',', map { $dbh->quote($_) } values %$r) . ")");
- }
-
- return $newid;
-}
-
sub create_style
{
- my ($u, $name, $cloneid) = @_;
+ my ( $u, $name ) = @_;
my $dbh = LJ::get_db_writer();
return 0 unless $dbh && $u->writer;
my $uid = $u->{userid} + 0
or return 0;
-
- my $clone;
- $clone = load_style($cloneid) if $cloneid;
-
- # can't clone somebody else's style
- return 0 if $clone && $clone->{'userid'} != $uid;
# can't create name-less style
return 0 unless $name =~ /\S/;
@@ -928,20 +884,6 @@ sub create_style
undef, $u->{'userid'}, $name);
my $styleid = $dbh->{'mysql_insertid'};
return 0 unless $styleid;
-
- if ($clone) {
- $clone->{'layer'}->{'user'} =
- LJ::clone_layer($clone->{'layer'}->{'user'});
-
- my $values;
- foreach my $ly ('core','i18nc','layout','theme','i18n','user') {
- next unless $clone->{'layer'}->{$ly};
- $values .= "," if $values;
- $values .= "($uid, $styleid, '$ly', $clone->{'layer'}->{$ly})";
- }
- $u->do("REPLACE INTO s2stylelayers2 (userid, styleid, type, s2lid) ".
- "VALUES $values") if $values;
- }
return $styleid;
}
@@ -985,9 +927,7 @@ sub delete_user_style
my $dbh = LJ::get_db_writer();
return 0 unless $dbh && $u->writer;
- foreach my $t (qw(s2styles s2stylelayers)) {
- $dbh->do("DELETE FROM $t WHERE styleid=?", undef, $styleid)
- }
+ $dbh->do("DELETE FROM s2styles WHERE styleid=?", undef, $styleid)
$u->do("DELETE FROM s2stylelayers2 WHERE userid=? AND styleid=?", undef,
$u->{userid}, $styleid);
@@ -1059,7 +999,7 @@ sub create_layer
}
# takes optional $u as first argument... if user argument is specified, will
-# look through s2stylelayers and delete all mappings that this user has to
+# look through s2stylelayers2 and delete all mappings that this user has to
# this particular layer.
sub delete_layer
{
@@ -1094,9 +1034,6 @@ sub delete_layer
# map in the ids we got from the user's styles and clear layers referencing
# this particular layer id
my $in = join(',', map { $_ + 0 } @ids);
- $dbh->do("DELETE FROM s2stylelayers WHERE styleid IN ($in) AND s2lid = ?",
- undef, $lid);
-
$u->do("DELETE FROM s2stylelayers2 WHERE userid=? AND styleid IN ($in) AND s2lid = ?",
undef, $u->{userid}, $lid);
@@ -1149,14 +1086,8 @@ sub get_style_layers
return 1;
};
- unless ($fetch->($u, "SELECT type, s2lid FROM s2stylelayers2 " .
- "WHERE userid=? AND styleid=?", $u->{userid}, $styleid)) {
- my $dbh = LJ::get_db_writer();
- if ($fetch->($dbh, "SELECT type, s2lid FROM s2stylelayers WHERE styleid=?",
- $styleid)) {
- LJ::S2::set_style_layers_raw($u, $styleid, %stylay);
- }
- }
+ $fetch->( $u, "SELECT type, s2lid FROM s2stylelayers2 " .
+ "WHERE userid=? AND styleid=?", $u->userid, $styleid );
# set in memcache
LJ::MemCache::set($memkey, \%stylay);
@@ -1164,43 +1095,7 @@ sub get_style_layers
return \%stylay;
}
-# the old interfaces. handles merging with global database data if necessary.
sub set_style_layers
-{
- my ($u, $styleid, %newlay) = @_;
- my $dbh = LJ::get_db_writer();
- return 0 unless $dbh && $u->writer;
-
- my @lay = ('core','i18nc','layout','theme','i18n','user');
- my %need = map { $_, 1 } @lay;
- delete $need{$_} foreach keys %newlay;
- if (%need) {
- # see if the needed layers are already on the user cluster
- my ($sth, $t, $lid);
-
- $sth = $u->prepare("SELECT type FROM s2stylelayers2 WHERE userid=? AND styleid=?");
- $sth->execute($u->{'userid'}, $styleid);
- while (($t) = $sth->fetchrow_array) {
- delete $need{$t};
- }
-
- # if we still don't have everything, see if they exist on the
- # global cluster, and we'll merge them into the %newlay being
- # posted, so they end up on the user cluster
- if (%need) {
- $sth = $dbh->prepare("SELECT type, s2lid FROM s2stylelayers WHERE styleid=?");
- $sth->execute($styleid);
- while (($t, $lid) = $sth->fetchrow_array) {
- $newlay{$t} = $lid;
- }
- }
- }
-
- set_style_layers_raw($u, $styleid, %newlay);
-}
-
-# just set in user cluster, not merging with global
-sub set_style_layers_raw {
my ($u, $styleid, %newlay) = @_;
my $dbh = LJ::get_db_writer();
return 0 unless $dbh && $u->writer;
@@ -1509,37 +1404,17 @@ sub load_layer_source
sub load_layer_source
{
my $s2lid = shift;
-
- # s2source is the old global MyISAM table that contains s2 layer sources
- # s2source_inno is new global InnoDB table that contains new layer sources
- # -- lazy migration is done whenever an insert/delete happens
-
my $dbh = LJ::get_db_writer();
- # first try InnoDB table
- my $s2source = $dbh->selectrow_array("SELECT s2code FROM s2source_inno WHERE s2lid=?", undef, $s2lid);
- return $s2source if $s2source;
-
- # fall back to MyISAM
- return $dbh->selectrow_array("SELECT s2code FROM s2source WHERE s2lid=?", undef, $s2lid);
+ return $dbh->selectrow_array( "SELECT s2code FROM s2source_inno WHERE s2lid=?", undef, $s2lid );
}
sub load_layer_source_row
{
my $s2lid = shift;
-
- # s2source is the old global MyISAM table that contains s2 layer sources
- # s2source_inno is new global InnoDB table that contains new layer sources
- # -- lazy migration is done whenever an insert/delete happens
-
my $dbh = LJ::get_db_writer();
- # first try InnoDB table
- my $s2source = $dbh->selectrow_hashref("SELECT * FROM s2source_inno WHERE s2lid=?", undef, $s2lid);
- return $s2source if $s2source;
-
- # fall back to MyISAM
- return $dbh->selectrow_hashref("SELECT * FROM s2source WHERE s2lid=?", undef, $s2lid);
+ return $dbh->selectrow_hashref( "SELECT * FROM s2source_inno WHERE s2lid=?", undef, $s2lid );
}
sub get_layout_langs
--------------------------------------------------------------------------------

no subject
no subject
no subject
no subject
no subject
It also looks fine in tropo, although long lines are truncated.
no subject
no subject
no subject