Commit cca45855 authored by Aurélien Campéas's avatar Aurélien Campéas
Browse files

connect -> begin (use transactions)

parent 5cf80e0007da
......@@ -177,7 +177,7 @@ def test_lots_of_diffs(engine, tracker, ptsh):
for day in range(1, days + 1):
date = utcdt(2017, month, day)
serie = genserie(date, '10Min', 6 * 24)
with engine.connect() as cn:
with engine.begin() as cn:
tsh.insert(cn, serie, 'manydiffs',
'aurelien.campeas@pythonian.fr',
_insertion_date=date.replace(year=2018)
......
......@@ -181,7 +181,7 @@ def test_differential(engine, tsh):
ts_longer.iloc[3] = 3.14
ts_longer.iloc[5] = ts_begin.iloc[7]
with engine.connect() as cn:
with engine.begin() as cn:
tsh.insert(cn, ts_longer, 'ts_test', 'test')
id3 = tsh.last_id(engine, 'ts_test')
......@@ -255,7 +255,7 @@ def test_differential(engine, tsh):
2010-01-07 3.0
""", tsh.get(engine, 'ts_mixte'))
with engine.connect() as cn:
with engine.begin() as cn:
cn.execute('set search_path to "{0}.timeserie", {0}, public'.format(tsh.namespace))
allts = pd.read_sql("select seriename, table_name from registry "
"where seriename in ('ts_test', 'ts_mixte')",
......@@ -374,7 +374,7 @@ def test_bad_import(engine, tsh):
def test_revision_date(engine, tsh):
for i in range(1, 5):
with engine.connect() as cn:
with engine.begin() as cn:
tsh.insert(cn, genserie(datetime(2017, 1, i), 'D', 3, [i]), 'revdate',
'test', _insertion_date=utcdt(2016, 1, i))
......@@ -620,7 +620,7 @@ Freq: D
def test_get_history(engine, tsh):
for numserie in (1, 2, 3):
with engine.connect() as cn:
with engine.begin() as cn:
tsh.insert(cn, genserie(datetime(2017, 1, 1), 'D', numserie), 'smallserie',
'aurelien.campeas@pythonian.fr',
_insertion_date=utcdt(2017, 2, numserie))
......@@ -672,7 +672,7 @@ insertion_date value_date
""", diffs)
for idate in histts:
with engine.connect() as cn:
with engine.begin() as cn:
idate = idate.replace(tzinfo=pytz.timezone('UTC'))
tsh.insert(cn, histts[idate], 'smallserie2',
'aurelien.campeas@pythonian.f', _insertion_date=idate)
......@@ -836,7 +836,7 @@ def test_nr_gethistory(engine, tsh):
freq='D'))
idate = utcdt(2016, 1, 1)
for i in range(5):
with engine.connect() as cn:
with engine.begin() as cn:
tsh.insert(cn, s1 * i, 'foo',
'aurelien.campeas@pythonian.f',
_insertion_date=idate + timedelta(days=i))
......@@ -948,7 +948,7 @@ def test_serie_deletion(engine, tsh):
seriecount, csetcount, csetseriecount = assert_structures(engine, tsh)
with engine.connect() as cn:
with engine.begin() as cn:
tsh.delete(cn, 'deleteme')
assert not tsh.exists(engine, 'deleteme')
......@@ -1016,7 +1016,7 @@ insertion_date value_date
""", h)
csid = tsh.changeset_at(engine, 'xserie', datetime(2017, 1, 3))
with engine.connect() as cn:
with engine.begin() as cn:
tsh.strip(cn, 'xserie', csid)
assert_hist("""
......
......@@ -12,7 +12,7 @@ from tshistory.helper import tempdir
def dump(dburi, dump_path, tsh, additional_dumping):
engine = create_engine(dburi)
with engine.connect() as cn:
with engine.begin() as cn:
logs = tsh.log(cn)
with tempdir() as temp_dir:
......@@ -23,7 +23,7 @@ def dump(dburi, dump_path, tsh, additional_dumping):
pd.DataFrame(logs).to_csv(str(temp_dir / 'registry.csv'))
for cset in logs:
csid = cset['rev']
with engine.connect() as cn:
with engine.begin() as cn:
cset_diff = tsh.log(cn, diff=True, fromrev=csid, torev=csid)[0]
for name in cset['names']:
......@@ -57,7 +57,7 @@ def restore(out_path, dburi, tsh, read_and_insert, additional_restoring):
with myzip.open(str(csid)) as cset_file:
cset_json = cset_file.read().decode('utf-8')
with engine.connect() as cn:
with engine.begin() as cn:
read_and_insert(cn, tsh, cset_json)
print(str(csid) + ' / ' + str(maxrevs))
......@@ -16,7 +16,7 @@ SCHEMAS = {}
meta = MetaData()
def delete_schema(engine, ns):
with engine.connect() as cn:
with engine.begin() as cn:
for subns in ('timeserie', 'snapshot'):
cn.execute(
'drop schema if exists "{}.{}" cascade'.format(ns, subns)
......
......@@ -133,7 +133,7 @@ def rename_series(engine, serie_map, namespace='tsh'):
schema = tsschema(namespace)
reg = schema.registry
with engine.connect() as cn:
with engine.begin() as cn:
for old, new in serie_map.items():
sql = reg.update().where(
reg.c.seriename == old
......
Supports Markdown
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