Skip to content

Commit bb4eeda

Browse files
committed
clean command
Signed-off-by: Soldy <[email protected]>
1 parent cd7f312 commit bb4eeda

File tree

3 files changed

+94
-9
lines changed

3 files changed

+94
-9
lines changed

src/openPanthera/containers.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,19 @@
4848

4949
short_commands = {
5050
'b' : 'build',
51+
'c' : 'clean',
5152
'd' : 'directory',
5253
'm' : 'migrate',
5354
's' : 'show'
5455
}
5556

57+
short_clean_commands = {
58+
'f' : 'function',
59+
'p' : 'procedure',
60+
't' : 'table',
61+
'v' : 'view'
62+
}
63+
5664
short_directory_commands = {
5765
'i' : 'init',
5866
'c' : 'check',
@@ -75,6 +83,7 @@
7583

7684
short_specific_commands = {
7785
'directory' : short_directory_commands,
86+
'clean' : short_clean_commands,
7887
'build' : short_types,
7988
'migrate' : short_migrate_commands,
8089
'show' : short_show_commands

src/openPanthera/mariadblib.py

Lines changed: 84 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,14 @@ def show(self, name:str):
9696
'function' : self._showFunctions
9797
}
9898
shows[name]()
99-
99+
def clean(self, name:str):
100+
cleans = {
101+
'function' : self._deleteAllFunctions,
102+
'procedure' : self._deleteAllProcedures,
103+
'table' : self._deleteAllTables,
104+
'view' : self._deleteAllViews
105+
}
106+
cleans[name]()
100107
def initMigrationTable(self):
101108
self._cur.execute(_table_query)
102109

@@ -147,7 +154,8 @@ def _cleanBuildScript(self, type_:str, file_name_:str):
147154
)
148155
self._conn.commit()
149156

150-
def _showProcedures(self):
157+
def _listProcedures(self):
158+
lista = []
151159
self._cur.execute(
152160
"SHOW PROCEDURE STATUS WHERE db = ?",
153161
[
@@ -167,10 +175,26 @@ def _showProcedures(self):
167175
collation_connection,
168176
coll
169177
) in self._cur:
178+
lista.append(Name)
179+
return lista
180+
def _showProcedures(self):
181+
for (
182+
Name
183+
) in self._listProcedures():
170184
self._p(f"{Name}")
171-
172-
173-
def _showFunctions(self):
185+
def _deleteProcedure(self, procedure:str):
186+
self._cur.execute(
187+
f"DROP PROCEDURE `{procedure}`;"
188+
)
189+
self._p(f"Delete procedure {procedure}")
190+
self._conn.commit()
191+
def _deleteAllProcedures(self):
192+
for (
193+
Name
194+
) in self._listProcedures():
195+
self._deleteProcedure(Name)
196+
def _listFunctions(self):
197+
lista = []
174198
self._cur.execute(
175199
"SHOW FUNCTION STATUS WHERE db = ?",
176200
[
@@ -190,19 +214,53 @@ def _showFunctions(self):
190214
collation_connection,
191215
coll
192216
) in self._cur:
217+
lista.append(Name)
218+
return lista
219+
def _showFunctions(self):
220+
for (
221+
Name
222+
) in self._listFunctions():
193223
self._p(f"{Name}")
194-
195-
def _showViews(self):
224+
def _deleteFunction(self, function:str):
225+
self._cur.execute(
226+
f"DROP FUNCTION `{function}`;"
227+
)
228+
self._p(f"Delete function {function}")
229+
self._conn.commit()
230+
def _deleteAllFunctions(self):
231+
for (
232+
Name
233+
) in self._listFunctions():
234+
self._deleteFunction(Name)
235+
def _listViews(self):
236+
lista = []
196237
self._cur.execute(
197238
"SHOW FULL TABLES WHERE Table_Type = 'VIEW'"
198239
)
199240
for (
200241
Name,
201242
Type
202243
) in self._cur:
244+
lista.append(Name)
245+
return lista
246+
def _showViews(self):
247+
for (
248+
Name
249+
) in self._listViews():
203250
self._p(f"{Name}")
204-
205-
def _showTables(self):
251+
def _deleteView(self, table:str):
252+
self._cur.execute(
253+
f"DROP VIEW IF EXISTS `{table}`;",
254+
)
255+
self._p(f"Delete table {table}")
256+
self._conn.commit()
257+
def _deleteAllViews(self):
258+
for (
259+
Name
260+
) in self._listViews():
261+
self._deleteView(Name)
262+
def _listTables(self):
263+
lista = []
206264
self._cur.execute(
207265
"SHOW FULL TABLES WHERE Table_Type = 'BASE TABLE'"
208266
)
@@ -211,5 +269,22 @@ def _showTables(self):
211269
Type
212270
) in self._cur:
213271
if Name != "panthera_migration":
272+
lista.append(Name)
273+
return lista
274+
def _showTables(self):
275+
for (
276+
Name
277+
) in self._listTables():
214278
self._p(f"{Name}")
279+
def _deleteTable(self, table:str):
280+
self._cur.execute(
281+
f"DROP TABLES IF EXISTS `{table}`;",
282+
)
283+
self._p(f"Delete table {table}")
284+
self._conn.commit()
285+
def _deleteAllTables(self):
286+
for (
287+
Name
288+
) in self._listTables():
289+
self._deleteTable(Name)
215290

src/openPanthera/schema.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def __init__(self, schema:str, ui):
3030
'migrate' : self._migrate.resolv,
3131
'init' : self._init,
3232
'build' : self._mariadb.build,
33+
'clean' : self._mariadb.clean,
3334
'directory': self._directory.resolv,
3435
'show' : self._mariadb.show
3536
}

0 commit comments

Comments
 (0)