Skip to content

Commit bda0c67

Browse files
davidrakerschandrika
authored andcommitted
Use primary key instead of unique constraint when creating data table.
1 parent cf83037 commit bda0c67

1 file changed

Lines changed: 10 additions & 11 deletions

File tree

volttron/platform/dbutils/postgresqlfuncts.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def rollback(self):
154154

155155
def setup_historian_tables(self):
156156
rows = self.select(f"""SELECT table_name FROM information_schema.tables
157-
WHERE table_catalog = '{self.db_name}' and table_schema = 'public'
157+
WHERE table_catalog = '{self.db_name}' and table_schema = 'public'
158158
AND table_name = '{self.data_table}'""")
159159
if rows:
160160
_log.debug("Found table {}. Historian table exists".format(
@@ -167,10 +167,10 @@ def setup_historian_tables(self):
167167
else:
168168
self.execute_stmt(SQL(
169169
'CREATE TABLE IF NOT EXISTS {} ('
170-
'ts TIMESTAMP NOT NULL, '
171-
'topic_id INTEGER NOT NULL, '
172-
'value_string TEXT NOT NULL, '
173-
'UNIQUE (topic_id, ts)'
170+
'ts TIMESTAMP NOT NULL, '
171+
'topic_id INTEGER NOT NULL, '
172+
'value_string TEXT NOT NULL, '
173+
'PRIMARY KEY (topic_id, ts)'
174174
')').format(Identifier(self.data_table)))
175175
if self.timescale_dialect:
176176
_log.debug("trying to create hypertable")
@@ -187,18 +187,17 @@ def setup_historian_tables(self):
187187
'CREATE INDEX IF NOT EXISTS {} ON {} (ts ASC)').format(
188188
Identifier('idx_' + self.data_table),
189189
Identifier(self.data_table)))
190-
191190
self.execute_stmt(SQL(
192191
'CREATE TABLE IF NOT EXISTS {} ('
193-
'topic_id SERIAL PRIMARY KEY NOT NULL, '
194-
'topic_name VARCHAR(512) NOT NULL, '
195-
'metadata TEXT, '
196-
'UNIQUE (topic_name)'
192+
'topic_id SERIAL PRIMARY KEY NOT NULL, '
193+
'topic_name VARCHAR(512) NOT NULL, '
194+
'metadata TEXT, '
195+
'UNIQUE (topic_name)'
197196
')').format(Identifier(self.topics_table)))
198197
# metadata is in topics table
199198
self.meta_table = self.topics_table
200199
self.commit()
201-
200+
202201
def setup_aggregate_historian_tables(self):
203202

204203
self.execute_stmt(SQL(

0 commit comments

Comments
 (0)