Commit 1f4e93c0 authored by Jérome Perrin's avatar Jérome Perrin

upgradeSchema: support changing table engine or comment

We were only checking if the defaut charset or default collation were
same, but if anything is different in the table options, we should
update it.

Also add a missing test for updating column comment
parent 4682955a
Pipeline #9788 passed with stage
......@@ -526,8 +526,7 @@ class DB(TM):
def _getTableSchema(self, name,
create_lstrip = re.compile(r"[^(]+\(\s*").sub,
create_rmatch = re.compile(r"(.*\S)\s*\)[^)]+\s"
"(DEFAULT(\s+(CHARSET|COLLATE)=\S+)+).*$", re.DOTALL).match,
create_rmatch = re.compile(r"(.*\S)\s*\)\s*(.*)$", re.DOTALL).match,
create_split = re.compile(r",\n\s*").split,
column_match = re.compile(r"`(\w+)`\s+(.+)").match,
):
......
......@@ -141,6 +141,29 @@ class TestTableStructureMigrationTestCase(ERP5TypeTestCase):
self.query("INSERT INTO X VALUES ()")
self.assertEqual((123,), self.query("SELECT a FROM X")[1][0])
def test_change_column_comment(self):
self.check_upgrade_schema(
dedent(
"""\
CREATE TABLE `X` (
`a` int(11) NOT NULL COMMENT 'old comment'
) ENGINE=InnoDB DEFAULT CHARSET=utf8"""),
dedent(
"""\
CREATE TABLE `X` (
`a` int(11) NOT NULL COMMENT 'new comment'
) ENGINE=InnoDB DEFAULT CHARSET=utf8"""))
self.assertEqual(
('a', 'new comment'),
self.query(
dedent(
"""\
SELECT COLUMN_NAME, COLUMN_COMMENT
FROM information_schema.COLUMNS
WHERE TABLE_NAME='X'
"""))[1][0],
)
def test_add_index(self):
self.check_upgrade_schema(
dedent(
......@@ -192,3 +215,49 @@ class TestTableStructureMigrationTestCase(ERP5TypeTestCase):
table_name='table')
self.query(
"SELECT `alter`, `and` FROM `table` USE INDEX (`use`)")
def test_change_table_engine(self):
self.check_upgrade_schema(
dedent(
"""\
CREATE TABLE `X` (
`a` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8"""),
dedent(
"""\
CREATE TABLE `X` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8"""))
self.assertEqual(
('X', 'InnoDB'),
self.query(
dedent(
"""\
SELECT TABLE_NAME, ENGINE
FROM information_schema.TABLES
WHERE TABLE_NAME='X'
"""))[1][0],
)
def test_change_table_comment(self):
self.check_upgrade_schema(
dedent(
"""\
CREATE TABLE `X` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='old comment'"""),
dedent(
"""\
CREATE TABLE `X` (
`a` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='new comment'"""))
self.assertEqual(
('X', 'new comment'),
self.query(
dedent(
"""\
SELECT TABLE_NAME, TABLE_COMMENT
FROM information_schema.TABLES
WHERE TABLE_NAME='X'
"""))[1][0],
)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment