sql: add possibility to drop formdef table (#17524)
This commit is contained in:
parent
8385a6798d
commit
c754ac53bc
|
@ -641,6 +641,30 @@ def test_sql_table_add_and_remove_fields():
|
|||
data_class = test_formdef.data_class(mode='sql')
|
||||
data_class.select()
|
||||
|
||||
@postgresql
|
||||
def test_sql_table_wipe_and_drop():
|
||||
test_formdef = FormDef()
|
||||
test_formdef.name = 'tests wipe and drop'
|
||||
test_formdef.fields = []
|
||||
test_formdef.store()
|
||||
assert test_formdef.table_name is not None
|
||||
data_class = test_formdef.data_class(mode='sql')
|
||||
assert data_class.count() == 0
|
||||
conn, cur = sql.get_connection_and_cursor()
|
||||
assert table_exists(cur, test_formdef.table_name)
|
||||
conn.commit()
|
||||
cur.close()
|
||||
|
||||
data_class.wipe(drop=True)
|
||||
conn, cur = sql.get_connection_and_cursor()
|
||||
assert not table_exists(cur, test_formdef.table_name)
|
||||
assert not table_exists(cur, test_formdef.table_name + '_evolutions')
|
||||
conn.commit()
|
||||
cur.close()
|
||||
|
||||
test_formdef.store()
|
||||
conn, cur = sql.get_connection_and_cursor()
|
||||
assert table_exists(cur, test_formdef.table_name)
|
||||
|
||||
@postgresql
|
||||
def test_sql_table_select():
|
||||
|
|
13
wcs/sql.py
13
wcs/sql.py
|
@ -1464,6 +1464,19 @@ class SqlFormData(SqlMixin, wcs.formdata.FormData):
|
|||
conn.commit()
|
||||
cur.close()
|
||||
|
||||
@classmethod
|
||||
@guard_postgres
|
||||
def wipe(cls, drop=False):
|
||||
conn, cur = get_connection_and_cursor()
|
||||
if drop:
|
||||
cur.execute('''DROP TABLE %s_evolutions CASCADE''' % cls._table_name)
|
||||
cur.execute('''DROP TABLE %s CASCADE''' % cls._table_name)
|
||||
else:
|
||||
cur.execute('''DELETE FROM %s_evolutions''' % cls._table_name)
|
||||
cur.execute('''DELETE FROM %s''' % cls._table_name)
|
||||
conn.commit()
|
||||
cur.close()
|
||||
|
||||
@classmethod
|
||||
def do_tracking_code_table(cls):
|
||||
do_tracking_code_table()
|
||||
|
|
Loading…
Reference in New Issue