<?php
function
IDF_Migrations_19WikiPageAssocs_up(
$params
=null)
{
$engine
= Pluf::f(
'db_engine'
);
if
(!in_array(
$engine
,
array
(
'MySQL'
,
'PostgreSQL'
))) {
throw
new
Exception(
'unsupported engine '
.
$engine
);
}
$db
= Pluf::db();
$intro
=
new
Pluf_DB_Introspect(
$db
);
if
(in_array(
$db
->pfx.
'idf_tag_idf_wiki_page_assoc'
,
$intro
->listTables())) {
echo
'19 skipping up migration - relation table has correct name already'
.
"\n"
;
return
;
}
$db
->execute(
'ALTER TABLE '
.
$db
->pfx.
'idf_tag_idf_wikipage_assoc RENAME TO '
.
$db
->pfx.
'idf_tag_idf_wiki_page_assoc'
);
$db
->execute(
'ALTER TABLE '
.
$db
->pfx.
'idf_wikipage_pluf_user_assoc RENAME TO '
.
$db
->pfx.
'idf_wiki_page_pluf_user_assoc'
);
if
(
$engine
===
'PostgreSQL'
) {
$db
->execute(
'ALTER TABLE '
.
$db
->pfx.
'idf_tag_idf_wiki_page_assoc RENAME COLUMN idf_wikipage_id TO idf_wiki_page_id'
);
$db
->execute(
'ALTER TABLE '
.
$db
->pfx.
'idf_wiki_page_pluf_user_assoc RENAME COLUMN idf_wikipage_id TO idf_wiki_page_id'
);
}
else
if
(
$engine
===
'MySQL'
) {
$db
->execute(
'ALTER TABLE '
.
$db
->pfx.
'idf_tag_idf_wiki_page_assoc CHANGE idf_wikipage_id idf_wiki_page_id MEDIUMINT NOT NULL'
);
$db
->execute(
'ALTER TABLE '
.
$db
->pfx.
'idf_wiki_page_pluf_user_assoc CHANGE idf_wikipage_id idf_wiki_page_id MEDIUMINT NOT NULL'
);
}
}
function
IDF_Migrations_19WikiPageAssocs_down(
$params
=null)
{
$engine
= Pluf::f(
'db_engine'
);
if
(!in_array(
$engine
,
array
(
'MySQL'
,
'PostgreSQL'
))) {
throw
new
Exception(
'unsupported engine '
.
$engine
);
}
$db
= Pluf::db();
$intro
=
new
Pluf_DB_Introspect(
$db
);
if
(in_array(
$db
->pfx.
'idf_tag_idf_wikipage_assoc'
,
$intro
->listTables())) {
echo
'19 skipping down migration - relation table has correct name already'
.
"\n"
;
return
;
}
$db
->execute(
'ALTER TABLE '
.
$db
->pfx.
'idf_tag_idf_wiki_page_assoc RENAME TO '
.
$db
->pfx.
'idf_tag_idf_wikipage_assoc'
);
$db
->execute(
'ALTER TABLE '
.
$db
->pfx.
'idf_wiki_page_pluf_user_assoc RENAME TO '
.
$db
->pfx.
'idf_wikipage_pluf_user_assoc'
);
if
(
$engine
===
'PostgreSQL'
) {
$db
->execute(
'ALTER TABLE '
.
$db
->pfx.
'idf_tag_idf_wikipage_assoc RENAME COLUMN idf_wiki_page_id TO idf_wikipage_id'
);
$db
->execute(
'ALTER TABLE '
.
$db
->pfx.
'idf_wikipage_pluf_user_assoc RENAME COLUMN idf_wiki_page_id TO idf_wikipage_id'
);
}
else
if
(
$engine
===
'MySQL'
) {
$db
->execute(
'ALTER TABLE '
.
$db
->pfx.
'idf_tag_idf_wikipage_assoc CHANGE idf_wiki_page_id idf_wikipage_id MEDIUMINT NOT NULL'
);
$db
->execute(
'ALTER TABLE '
.
$db
->pfx.
'idf_wikipage_pluf_user_assoc CHANGE idf_wiki_page_id idf_wikipage_id MEDIUMINT NOT NULL'
);
}
}