Lock column updates
This commit is contained in:
parent
894819fe99
commit
a513888824
@ -56,6 +56,7 @@ class Table(object):
|
|||||||
"""Get a dictionary of all columns and their case mapping."""
|
"""Get a dictionary of all columns and their case mapping."""
|
||||||
if not self.exists:
|
if not self.exists:
|
||||||
return {}
|
return {}
|
||||||
|
with self.db.lock:
|
||||||
if self._columns is None:
|
if self._columns is None:
|
||||||
# Initialise the table if it doesn't exist
|
# Initialise the table if it doesn't exist
|
||||||
table = self.table
|
table = self.table
|
||||||
@ -68,6 +69,10 @@ class Table(object):
|
|||||||
self._columns[key] = name
|
self._columns[key] = name
|
||||||
return self._columns
|
return self._columns
|
||||||
|
|
||||||
|
def _flush_metadata(self):
|
||||||
|
with self.db.lock:
|
||||||
|
self._columns = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def columns(self):
|
def columns(self):
|
||||||
"""Get a listing of all columns that exist in the table."""
|
"""Get a listing of all columns that exist in the table."""
|
||||||
@ -305,7 +310,7 @@ class Table(object):
|
|||||||
def _reflect_table(self):
|
def _reflect_table(self):
|
||||||
"""Load the tables definition from the database."""
|
"""Load the tables definition from the database."""
|
||||||
with self.db.lock:
|
with self.db.lock:
|
||||||
self._columns = None
|
self._flush_metadata()
|
||||||
try:
|
try:
|
||||||
self._table = SQLATable(self.name,
|
self._table = SQLATable(self.name,
|
||||||
self.db.metadata,
|
self.db.metadata,
|
||||||
@ -323,7 +328,7 @@ class Table(object):
|
|||||||
|
|
||||||
def _sync_table(self, columns):
|
def _sync_table(self, columns):
|
||||||
"""Lazy load, create or adapt the table structure in the database."""
|
"""Lazy load, create or adapt the table structure in the database."""
|
||||||
self._columns = None
|
self._flush_metadata()
|
||||||
if self._table is None:
|
if self._table is None:
|
||||||
# Load an existing table from the database.
|
# Load an existing table from the database.
|
||||||
self._reflect_table()
|
self._reflect_table()
|
||||||
@ -520,7 +525,7 @@ class Table(object):
|
|||||||
self._threading_warn()
|
self._threading_warn()
|
||||||
self.table.drop(self.db.executable, checkfirst=True)
|
self.table.drop(self.db.executable, checkfirst=True)
|
||||||
self._table = None
|
self._table = None
|
||||||
self._columns = None
|
self._flush_metadata()
|
||||||
|
|
||||||
def has_index(self, columns):
|
def has_index(self, columns):
|
||||||
"""Check if an index exists to cover the given ``columns``."""
|
"""Check if an index exists to cover the given ``columns``."""
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user