Skip to content

Commit 847e245

Browse files
committed
WL11303: Remove CreateTable and CreateView
This worklogs removes the methods from Schema for creating/droping tables and for creating/droping/altering views. Tests and documentation were changed accordingly.
1 parent bfcac33 commit 847e245

12 files changed

+56
-1315
lines changed

docs/mysqlx/mysqlx.AlterViewStatement.rst

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/mysqlx/mysqlx.ColumnDef.rst

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/mysqlx/mysqlx.CreateTableStatement.rst

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/mysqlx/mysqlx.CreateViewStatement.rst

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/mysqlx/mysqlx.ForeignKeyDef.rst

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/mysqlx/mysqlx.GeneratedColumnDef.rst

Lines changed: 0 additions & 8 deletions
This file was deleted.

docs/mysqlx/mysqlx.rst

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,6 @@ Statement
5353
mysqlx.DeleteStatement
5454
mysqlx.UpdateStatement
5555
mysqlx.CreateCollectionIndexStatement
56-
mysqlx.CreateTableStatement
57-
mysqlx.ColumnDef
58-
mysqlx.GeneratedColumnDef
59-
mysqlx.ForeignKeyDef
60-
mysqlx.CreateViewStatement
61-
mysqlx.AlterViewStatement
6256
mysqlx.ReadStatement
6357
mysqlx.WriteStatement
6458

lib/mysqlx/__init__.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,8 @@
4242
FindStatement, AddStatement, RemoveStatement,
4343
ModifyStatement, SelectStatement, InsertStatement,
4444
DeleteStatement, UpdateStatement,
45-
CreateCollectionIndexStatement, CreateTableStatement,
46-
CreateViewStatement, AlterViewStatement, ColumnDef,
47-
GeneratedColumnDef, ForeignKeyDef, Expr,
48-
ReadStatement, WriteStatement)
45+
CreateCollectionIndexStatement, Expr, ReadStatement,
46+
WriteStatement)
4947

5048
_SPLIT = re.compile(r',(?![^\(\)]*\))')
5149
_PRIORITY = re.compile(r'^\(address=(.+),priority=(\d+)\)$', re.VERBOSE)
@@ -296,7 +294,5 @@ def get_session(*args, **kwargs):
296294
"DbDoc", "Statement", "FilterableStatement", "SqlStatement",
297295
"FindStatement", "AddStatement", "RemoveStatement", "ModifyStatement",
298296
"SelectStatement", "InsertStatement", "DeleteStatement", "UpdateStatement",
299-
"CreateCollectionIndexStatement", "CreateTableStatement",
300-
"CreateViewStatement", "AlterViewStatement", "ColumnDef",
301-
"GeneratedColumnDef", "ForeignKeyDef", "Expr",
297+
"CreateCollectionIndexStatement", "Expr",
302298
]

lib/mysqlx/constants.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,11 @@ def create_enum(name, fields, values=None):
4444
return Enum(*values)
4545

4646

47-
Algorithms = create_enum("Algorithms", ("MERGE", "TMPTABLE", "UNDEFINED"))
48-
Securities = create_enum("Securities", ("DEFINER", "INVOKER"))
49-
CheckOptions = create_enum("CheckOptions", ("CASCADED", "LOCAL"))
5047
SSLMode = create_enum("SSLMode",
5148
("REQUIRED", "DISABLED", "VERIFY_CA", "VERIFY_IDENTITY"),
5249
("required", "disabled", "verify_ca", "verify_identity"))
5350
Auth = create_enum("Auth",
5451
("PLAIN", "EXTERNAL", "MYSQL41"),
5552
("plain", "external", "mysql41"))
5653

57-
__all__ = ["Algorithms", "Securities", "CheckOptions", "SSLMode", "Auth"]
54+
__all__ = ["SSLMode", "Auth"]

lib/mysqlx/crud.py

Lines changed: 1 addition & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@
2828
from .statement import (FindStatement, AddStatement, RemoveStatement,
2929
ModifyStatement, SelectStatement, InsertStatement,
3030
DeleteStatement, UpdateStatement,
31-
CreateCollectionIndexStatement, CreateViewStatement,
32-
AlterViewStatement, CreateTableStatement)
31+
CreateCollectionIndexStatement)
3332

3433

3534
_COUNT_VIEWS_QUERY = ("SELECT COUNT(*) FROM information_schema.views "
@@ -40,7 +39,6 @@
4039
"WHERE schema_name like '{0}'")
4140
_COUNT_QUERY = "SELECT COUNT(*) FROM `{0}`.`{1}`"
4241
_DROP_TABLE_QUERY = "DROP TABLE IF EXISTS `{0}`.`{1}`"
43-
_DROP_VIEW_QUERY = "DROP VIEW IF EXISTS `{0}`.`{1}`"
4442

4543

4644
class DatabaseObject(object):
@@ -243,28 +241,6 @@ def drop_collection(self, name):
243241
self._connection.execute_nonquery(
244242
"sql", _DROP_TABLE_QUERY.format(self._name, name), False)
245243

246-
def drop_table(self, name):
247-
"""Drops a table.
248-
249-
Args:
250-
name (str): The name of the table to be dropped.
251-
"""
252-
table = Table(self, name)
253-
if table.is_view():
254-
self.drop_view(name)
255-
else:
256-
self._connection.execute_nonquery(
257-
"sql", _DROP_TABLE_QUERY.format(self._name, name), False)
258-
259-
def drop_view(self, name):
260-
"""Drops a view.
261-
262-
Args:
263-
name (str): The name of the view to be dropped.
264-
"""
265-
self._connection.execute_nonquery(
266-
"sql", _DROP_VIEW_QUERY.format(self._name, name), False)
267-
268244
def create_collection(self, name, reuse=False):
269245
"""Creates in the current schema a new collection with the specified
270246
name and retrieves an object representing the new collection created.
@@ -290,53 +266,6 @@ def create_collection(self, name, reuse=False):
290266
raise ProgrammingError("Collection already exists")
291267
return collection
292268

293-
def create_view(self, name, replace=False):
294-
"""Creates in the current schema a new view with the specified name
295-
and retrieves an object representing the new view created.
296-
297-
Args:
298-
name (string): The name of the view.
299-
replace (Optional[bool]): `True` to add replace.
300-
301-
Returns:
302-
mysqlx.View: View object.
303-
"""
304-
view = View(self, name)
305-
return view.get_create_statement(replace)
306-
307-
def alter_view(self, name):
308-
"""Alters a view in the current schema with the specified name and
309-
retrieves an object representing the view.
310-
311-
Args:
312-
name (string): The name of the view.
313-
314-
Returns:
315-
mysqlx.View: View object.
316-
"""
317-
view = View(self, name)
318-
return view.get_alter_statement()
319-
320-
def create_table(self, name, reuse=False):
321-
"""Creates in the current schema a table with the specified name and
322-
retrieves an object representing the new table created.
323-
324-
Args:
325-
name (string): The name of the name.
326-
reuse (Optional[bool]): `True` to reuse.
327-
328-
Returns:
329-
mysqlx.Table: Table object.
330-
"""
331-
if not name:
332-
raise ProgrammingError("Table name is invalid")
333-
table = Table(self, name)
334-
if not table.exists_in_database():
335-
return CreateTableStatement(self, name)
336-
elif not reuse:
337-
raise ProgrammingError("Table already exists")
338-
return table
339-
340269

341270
class Collection(DatabaseObject):
342271
"""Represents a collection of documents on a schema.
@@ -577,22 +506,3 @@ def exists_in_database(self):
577506
"""
578507
sql = _COUNT_VIEWS_QUERY.format(self._schema.name, self._name)
579508
return self._connection.execute_sql_scalar(sql) == 1
580-
581-
def get_create_statement(self, replace=False):
582-
"""Creates a new :class:`mysqlx.CreateViewStatement` object.
583-
584-
Args:
585-
replace (Optional[bool]): `True` to add replace.
586-
587-
Returns:
588-
mysqlx.CreateViewStatement: CreateViewStatement object.
589-
"""
590-
return CreateViewStatement(self, replace)
591-
592-
def get_alter_statement(self):
593-
"""Creates a new :class:`mysqlx.AlterViewStatement` object.
594-
595-
Returns:
596-
mysqlx.AlterViewStatement: AlterViewStatement object.
597-
"""
598-
return AlterViewStatement(self)

0 commit comments

Comments
 (0)