1) Wrong tablespace displayed in table properties. Fixes #2069

2) Message (Connection to the server has been lost.) displayed with Materialized view and view under sql tab. Fixes #2139
This commit is contained in:
Khushboo Vashi 2017-02-03 16:13:07 +05:30 committed by Akshay Joshi
parent 4ef26a528b
commit f2ac6fc6a7
18 changed files with 123 additions and 78 deletions

View File

@ -134,7 +134,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
- This function is used to return modified SQL for the selected - This function is used to return modified SQL for the selected
Table node Table node
* get_sql(data, scid, tid) * get_sql(did, scid, tid, data)
- This function will generate sql from model data - This function will generate sql from model data
* sql(gid, sid, did, scid, tid): * sql(gid, sid, did, scid, tid):
@ -182,7 +182,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
- It will return formatted output of query result - It will return formatted output of query result
as per client model format for column node as per client model format for column node
* _index_constraints_formatter(self, tid, data): * _index_constraints_formatter(self, did, tid, data):
- It will return formatted output of query result - It will return formatted output of query result
as per client model format for index constraint node as per client model format for index constraint node
@ -195,7 +195,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
- This function will parse and return formatted list of columns - This function will parse and return formatted list of columns
added by user added by user
* get_index_constraint_sql(self, tid, data): * get_index_constraint_sql(self, did, tid, data):
- This function will generate modified sql for index constraints - This function will generate modified sql for index constraints
(Primary Key & Unique) (Primary Key & Unique)
@ -332,7 +332,8 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
""" """
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
scid=scid, datlastsysoid=self.datlastsysoid) did=did, scid=scid,
datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
if not status: if not status:
@ -725,7 +726,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
return data return data
def _index_constraints_formatter(self, tid, data): def _index_constraints_formatter(self, did, tid, data):
""" """
Args: Args:
tid: Table OID tid: Table OID
@ -746,7 +747,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
sql = render_template("/".join([self.index_constraint_template_path, sql = render_template("/".join([self.index_constraint_template_path,
'properties.sql']), 'properties.sql']),
tid=tid, did=did, tid=tid,
constraint_type=ctype) constraint_type=ctype)
status, res = self.conn.execute_dict(sql) status, res = self.conn.execute_dict(sql)
@ -874,7 +875,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
return data return data
def _exclusion_constraint_formatter(self, tid, data): def _exclusion_constraint_formatter(self, did, tid, data):
""" """
Args: Args:
tid: Table OID tid: Table OID
@ -888,7 +889,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
# We will fetch all the index constraints for the table # We will fetch all the index constraints for the table
sql = render_template("/".join([self.exclusion_constraint_template_path, sql = render_template("/".join([self.exclusion_constraint_template_path,
'properties.sql']), 'properties.sql']),
tid=tid) did=did, tid=tid)
status, result = self.conn.execute_dict(sql) status, result = self.conn.execute_dict(sql)
@ -971,7 +972,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
return None return None
def _formatter(self, scid, tid, data): def _formatter(self, did, scid, tid, data):
""" """
Args: Args:
data: dict of query result data: dict of query result
@ -1090,10 +1091,10 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
data = self._columns_formatter(tid, data) data = self._columns_formatter(tid, data)
# Here we will add constraint in our output # Here we will add constraint in our output
data = self._index_constraints_formatter(tid, data) data = self._index_constraints_formatter(did, tid, data)
data = self._foreign_key_formatter(tid, data) data = self._foreign_key_formatter(tid, data)
data = self._check_constraint_formatter(tid, data) data = self._check_constraint_formatter(tid, data)
data = self._exclusion_constraint_formatter(tid, data) data = self._exclusion_constraint_formatter(did, tid, data)
return data return data
@ -1116,7 +1117,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
scid=scid, tid=tid, did=did, scid=scid, tid=tid,
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
if not status: if not status:
@ -1139,7 +1140,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
'vacuum_settings_str' 'vacuum_settings_str'
].replace("=", " = ") ].replace("=", " = ")
data = self._formatter(scid, tid, data) data = self._formatter(did, scid, tid, data)
return ajax_response( return ajax_response(
response=data, response=data,
@ -1486,7 +1487,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
data[k] = v data[k] = v
try: try:
SQL, name = self.get_sql(scid, tid, data) SQL, name = self.get_sql(did, scid, tid, data)
SQL = SQL.strip('\n').strip(' ') SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL) status, res = self.conn.execute_scalar(SQL)
@ -1535,7 +1536,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
try: try:
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
scid=scid, tid=tid, did=did, scid=scid, tid=tid,
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
if not status: if not status:
@ -1596,7 +1597,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
try: try:
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
scid=scid, tid=tid, did=did, scid=scid, tid=tid,
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
if not status: if not status:
@ -1644,7 +1645,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
try: try:
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
scid=scid, tid=tid, did=did, scid=scid, tid=tid,
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
if not status: if not status:
@ -1724,7 +1725,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
data[k] = v data[k] = v
try: try:
SQL, name = self.get_sql(scid, tid, data) SQL, name = self.get_sql(did, scid, tid, data)
SQL = re.sub('\n{2,}', '\n\n', SQL) SQL = re.sub('\n{2,}', '\n\n', SQL)
SQL = SQL.strip('\n') SQL = SQL.strip('\n')
if SQL == '': if SQL == '':
@ -1736,7 +1737,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
except Exception as e: except Exception as e:
return internal_server_error(errormsg=str(e)) return internal_server_error(errormsg=str(e))
def get_index_constraint_sql(self, tid, data): def get_index_constraint_sql(self, did, tid, data):
""" """
Args: Args:
tid: Table ID tid: Table ID
@ -1778,7 +1779,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
properties_sql = render_template("/".join( properties_sql = render_template("/".join(
[self.index_constraint_template_path, 'properties.sql']), [self.index_constraint_template_path, 'properties.sql']),
tid=tid, cid=c['oid'], constraint_type=ctype) did=did, tid=tid, cid=c['oid'], constraint_type=ctype)
status, res = self.conn.execute_dict(properties_sql) status, res = self.conn.execute_dict(properties_sql)
if not status: if not status:
return internal_server_error(errormsg=res) return internal_server_error(errormsg=res)
@ -2092,7 +2093,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
else: else:
return None return None
def get_sql(self, scid, tid, data): def get_sql(self, did, scid, tid, data):
""" """
This function will generate create/update sql from model data This function will generate create/update sql from model data
coming from client coming from client
@ -2100,14 +2101,14 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
if tid is not None: if tid is not None:
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
scid=scid, tid=tid, did=did, scid=scid, tid=tid,
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
if not status: if not status:
return internal_server_error(errormsg=res) return internal_server_error(errormsg=res)
old_data = res['rows'][0] old_data = res['rows'][0]
old_data = self._formatter(scid, tid, old_data) old_data = self._formatter(did, scid, tid, old_data)
# We will convert privileges coming from client required # We will convert privileges coming from client required
if 'relacl' in data: if 'relacl' in data:
@ -2259,7 +2260,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
SQL += column_sql.strip('\n') SQL += column_sql.strip('\n')
# Check if index constraints are added/changed/deleted # Check if index constraints are added/changed/deleted
index_constraint_sql = self.get_index_constraint_sql(tid, data) index_constraint_sql = self.get_index_constraint_sql(did, tid, data)
# If we have index constraint sql then ad it in main sql # If we have index constraint sql then ad it in main sql
if index_constraint_sql is not None: if index_constraint_sql is not None:
SQL += '\n' + index_constraint_sql SQL += '\n' + index_constraint_sql
@ -2456,7 +2457,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
""" """
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
scid=scid, tid=tid, did=did, scid=scid, tid=tid,
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
if not status: if not status:
@ -2468,7 +2469,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
schema = data['schema'] schema = data['schema']
table = data['name'] table = data['name']
data = self._formatter(scid, tid, data) data = self._formatter(did, scid, tid, data)
# Now we have all lis of columns which we need # Now we have all lis of columns which we need
# to include in our create definition, Let's format them # to include in our create definition, Let's format them
@ -2524,7 +2525,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
SQL = render_template("/".join([self.index_template_path, SQL = render_template("/".join([self.index_template_path,
'properties.sql']), 'properties.sql']),
tid=tid, idx=row['oid'], did=did, tid=tid, idx=row['oid'],
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
@ -2726,14 +2727,14 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
""" """
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
scid=scid, tid=tid, did=did, scid=scid, tid=tid,
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
if not status: if not status:
return internal_server_error(errormsg=res) return internal_server_error(errormsg=res)
data = res['rows'][0] data = res['rows'][0]
data = self._formatter(scid, tid, data) data = self._formatter(did, scid, tid, data)
columns = [] columns = []
@ -2770,14 +2771,14 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
""" """
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
scid=scid, tid=tid, did=did, scid=scid, tid=tid,
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
if not status: if not status:
return internal_server_error(errormsg=res) return internal_server_error(errormsg=res)
data = res['rows'][0] data = res['rows'][0]
data = self._formatter(scid, tid, data) data = self._formatter(did, scid, tid, data)
columns = [] columns = []
values = [] values = []
@ -2817,14 +2818,14 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
""" """
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
scid=scid, tid=tid, did=did, scid=scid, tid=tid,
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
if not status: if not status:
return internal_server_error(errormsg=res) return internal_server_error(errormsg=res)
data = res['rows'][0] data = res['rows'][0]
data = self._formatter(scid, tid, data) data = self._formatter(did, scid, tid, data)
columns = [] columns = []
@ -2866,7 +2867,7 @@ class TableView(PGChildNodeView, DataTypeReader, VacuumSettings):
""" """
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
scid=scid, tid=tid, did=did, scid=scid, tid=tid,
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
if not status: if not status:

View File

@ -266,7 +266,7 @@ class ExclusionConstraintView(PGChildNodeView):
""" """
sql = render_template("/".join([self.template_path, 'properties.sql']), sql = render_template("/".join([self.template_path, 'properties.sql']),
tid=tid, cid=exid) did=did, tid=tid, cid=exid)
status, res = self.conn.execute_dict(sql) status, res = self.conn.execute_dict(sql)
@ -374,6 +374,7 @@ class ExclusionConstraintView(PGChildNodeView):
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
did=did,
tid=tid) tid=tid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
@ -635,7 +636,7 @@ class ExclusionConstraintView(PGChildNodeView):
try: try:
data['schema'] = self.schema data['schema'] = self.schema
data['table'] = self.table data['table'] = self.table
sql, name = self.get_sql(data, tid, exid) sql, name = self.get_sql(data, did, tid, exid)
sql = sql.strip('\n').strip(' ') sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql) status, res = self.conn.execute_scalar(sql)
if not status: if not status:
@ -750,7 +751,7 @@ class ExclusionConstraintView(PGChildNodeView):
data['schema'] = self.schema data['schema'] = self.schema
data['table'] = self.table data['table'] = self.table
try: try:
sql, name = self.get_sql(data, tid, exid) sql, name = self.get_sql(data, did, tid, exid)
sql = sql.strip('\n').strip(' ') sql = sql.strip('\n').strip(' ')
if sql == '': if sql == '':
sql = "--modified SQL" sql = "--modified SQL"
@ -762,7 +763,7 @@ class ExclusionConstraintView(PGChildNodeView):
except Exception as e: except Exception as e:
return internal_server_error(errormsg=str(e)) return internal_server_error(errormsg=str(e))
def get_sql(self, data, tid, exid=None): def get_sql(self, data, did, tid, exid=None):
""" """
This function will generate sql from model data. This function will generate sql from model data.
@ -776,6 +777,7 @@ class ExclusionConstraintView(PGChildNodeView):
""" """
if exid is not None: if exid is not None:
sql = render_template("/".join([self.template_path, 'properties.sql']), sql = render_template("/".join([self.template_path, 'properties.sql']),
did=did,
tid=tid, tid=tid,
cid=exid) cid=exid)
status, res = self.conn.execute_dict(sql) status, res = self.conn.execute_dict(sql)
@ -824,7 +826,7 @@ class ExclusionConstraintView(PGChildNodeView):
try: try:
SQL = render_template( SQL = render_template(
"/".join([self.template_path, 'properties.sql']), "/".join([self.template_path, 'properties.sql']),
tid=tid, conn=self.conn, cid=exid) did=did, tid=tid, conn=self.conn, cid=exid)
status, result = self.conn.execute_dict(SQL) status, result = self.conn.execute_dict(SQL)
if not status: if not status:
return internal_server_error(errormsg=result) return internal_server_error(errormsg=result)
@ -912,7 +914,7 @@ class ExclusionConstraintView(PGChildNodeView):
# Fetch index details only if extended stats available # Fetch index details only if extended stats available
SQL = render_template( SQL = render_template(
"/".join([self.template_path, 'properties.sql']), "/".join([self.template_path, 'properties.sql']),
tid=tid, conn=self.conn, cid=exid) did=did, tid=tid, conn=self.conn, cid=exid)
status, result = self.conn.execute_dict(SQL) status, result = self.conn.execute_dict(SQL)
if not status: if not status:
return internal_server_error(errormsg=result) return internal_server_error(errormsg=result)

View File

@ -653,7 +653,7 @@ function($, _, S, pgAdmin, pgBrowser, Alertify) {
name: undefined, name: undefined,
oid: undefined, oid: undefined,
comment: undefined, comment: undefined,
spcname: "pg_default", spcname: undefined,
amname: "gist", amname: "gist",
fillfactor: undefined, fillfactor: undefined,
condeferrable: undefined, condeferrable: undefined,

View File

@ -285,6 +285,7 @@ class IndexConstraintView(PGChildNodeView):
""" """
sql = render_template("/".join([self.template_path, 'properties.sql']), sql = render_template("/".join([self.template_path, 'properties.sql']),
did=did,
tid=tid, tid=tid,
cid=cid, cid=cid,
constraint_type=self.constraint_type) constraint_type=self.constraint_type)
@ -381,6 +382,7 @@ class IndexConstraintView(PGChildNodeView):
self.table = row['table'] self.table = row['table']
SQL = render_template("/".join([self.template_path, 'properties.sql']), SQL = render_template("/".join([self.template_path, 'properties.sql']),
did=did,
tid=tid, tid=tid,
constraint_type=self.constraint_type) constraint_type=self.constraint_type)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
@ -664,7 +666,7 @@ class IndexConstraintView(PGChildNodeView):
try: try:
data['schema'] = self.schema data['schema'] = self.schema
data['table'] = self.table data['table'] = self.table
sql, name = self.get_sql(data, tid, cid) sql, name = self.get_sql(data, did, tid, cid)
sql = sql.strip('\n').strip(' ') sql = sql.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(sql) status, res = self.conn.execute_scalar(sql)
@ -784,7 +786,7 @@ class IndexConstraintView(PGChildNodeView):
data['schema'] = self.schema data['schema'] = self.schema
data['table'] = self.table data['table'] = self.table
try: try:
sql, name = self.get_sql(data, tid, cid) sql, name = self.get_sql(data, did, tid, cid)
sql = sql.strip('\n').strip(' ') sql = sql.strip('\n').strip(' ')
if sql == '': if sql == '':
sql = "--modified SQL" sql = "--modified SQL"
@ -796,7 +798,7 @@ class IndexConstraintView(PGChildNodeView):
except Exception as e: except Exception as e:
return internal_server_error(errormsg=str(e)) return internal_server_error(errormsg=str(e))
def get_sql(self, data, tid, cid=None): def get_sql(self, data, did, tid, cid=None):
""" """
This function will generate sql from model data. This function will generate sql from model data.
@ -810,6 +812,7 @@ class IndexConstraintView(PGChildNodeView):
""" """
if cid is not None: if cid is not None:
sql = render_template("/".join([self.template_path, 'properties.sql']), sql = render_template("/".join([self.template_path, 'properties.sql']),
did=did,
tid=tid, tid=tid,
cid=cid, cid=cid,
constraint_type=self.constraint_type) constraint_type=self.constraint_type)
@ -873,6 +876,7 @@ class IndexConstraintView(PGChildNodeView):
try: try:
SQL = render_template( SQL = render_template(
"/".join([self.template_path, 'properties.sql']), "/".join([self.template_path, 'properties.sql']),
did=did,
tid=tid, tid=tid,
conn=self.conn, conn=self.conn,
cid=cid, cid=cid,
@ -950,6 +954,7 @@ class IndexConstraintView(PGChildNodeView):
if is_pgstattuple: if is_pgstattuple:
# Fetch index details only if extended stats available # Fetch index details only if extended stats available
sql = render_template("/".join([self.template_path, 'properties.sql']), sql = render_template("/".join([self.template_path, 'properties.sql']),
did=did,
tid=tid, tid=tid,
cid=cid, cid=cid,
constraint_type=self.constraint_type) constraint_type=self.constraint_type)

View File

@ -85,7 +85,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
name: undefined, name: undefined,
oid: undefined, oid: undefined,
comment: undefined, comment: undefined,
spcname: "pg_default", spcname: undefined,
index: undefined, index: undefined,
fillfactor: undefined, fillfactor: undefined,
condeferrable: undefined, condeferrable: undefined,

View File

@ -521,7 +521,7 @@ class IndexesView(PGChildNodeView):
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
tid=tid, idx=idx, did=did, tid=tid, idx=idx,
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
@ -665,7 +665,7 @@ class IndexesView(PGChildNodeView):
# so that we create template for dropping index # so that we create template for dropping index
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
tid=tid, idx=idx, did=did, tid=tid, idx=idx,
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
@ -723,7 +723,7 @@ class IndexesView(PGChildNodeView):
data['schema'] = self.schema data['schema'] = self.schema
data['table'] = self.table data['table'] = self.table
try: try:
SQL, name = self.get_sql(scid, tid, idx, data) SQL, name = self.get_sql(did, scid, tid, idx, data)
SQL = SQL.strip('\n').strip(' ') SQL = SQL.strip('\n').strip(' ')
status, res = self.conn.execute_scalar(SQL) status, res = self.conn.execute_scalar(SQL)
if not status: if not status:
@ -765,7 +765,7 @@ class IndexesView(PGChildNodeView):
data['table'] = self.table data['table'] = self.table
try: try:
sql, name = self.get_sql(scid, tid, idx, data, mode='create') sql, name = self.get_sql(did, scid, tid, idx, data, mode='create')
sql = sql.strip('\n').strip(' ') sql = sql.strip('\n').strip(' ')
if sql == '': if sql == '':
sql = "--modified SQL" sql = "--modified SQL"
@ -776,14 +776,14 @@ class IndexesView(PGChildNodeView):
except Exception as e: except Exception as e:
return internal_server_error(errormsg=str(e)) return internal_server_error(errormsg=str(e))
def get_sql(self, scid, tid, idx, data, mode=None): def get_sql(self, did, scid, tid, idx, data, mode=None):
""" """
This function will genrate sql from model data This function will genrate sql from model data
""" """
if idx is not None: if idx is not None:
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
tid=tid, idx=idx, did=did, tid=tid, idx=idx,
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
@ -842,7 +842,7 @@ class IndexesView(PGChildNodeView):
try: try:
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
tid=tid, idx=idx, did=did, tid=tid, idx=idx,
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
@ -857,7 +857,7 @@ class IndexesView(PGChildNodeView):
# Add column details for current index # Add column details for current index
data = self._column_details(idx, data) data = self._column_details(idx, data)
SQL, name = self.get_sql(scid, tid, None, data) SQL, name = self.get_sql(did, scid, tid, None, data)
sql_header = "-- Index: {0}\n\n-- ".format(data['name']) sql_header = "-- Index: {0}\n\n-- ".format(data['name'])
if hasattr(str, 'decode'): if hasattr(str, 'decode'):
@ -955,7 +955,7 @@ class IndexesView(PGChildNodeView):
# Fetch index details only if extended stats available # Fetch index details only if extended stats available
SQL = render_template("/".join([self.template_path, SQL = render_template("/".join([self.template_path,
'properties.sql']), 'properties.sql']),
tid=tid, idx=idx, did=did, tid=tid, idx=idx,
datlastsysoid=self.datlastsysoid) datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
if not status: if not status:

View File

@ -259,7 +259,7 @@ function($, _, S, pgAdmin, pgBrowser, Backform, alertify) {
oid: undefined, oid: undefined,
nspname: undefined, nspname: undefined,
tabname: undefined, tabname: undefined,
spcname: 'pg_default', spcname: undefined,
amname: 'btree' amname: 'btree'
}, },
schema: [{ schema: [{

View File

@ -2,7 +2,11 @@ SELECT cls.oid,
cls.relname as name, cls.relname as name,
indnatts, indnatts,
amname, amname,
COALESCE(spcname, 'pg_default') as spcname, CASE WHEN length(spcname) > 0 THEN spcname ELSE
(SELECT sp.spcname FROM pg_database dtb
JOIN pg_tablespace sp ON dtb.dattablespace=sp.oid
WHERE dtb.oid = {{ did }}::oid)
END as spcname,
CASE contype CASE contype
WHEN 'p' THEN desp.description WHEN 'p' THEN desp.description
WHEN 'u' THEN desp.description WHEN 'u' THEN desp.description

View File

@ -1,6 +1,11 @@
SELECT DISTINCT ON(cls.relname) cls.oid, cls.relname as name, indrelid, indkey, indisclustered, SELECT DISTINCT ON(cls.relname) cls.oid, cls.relname as name, indrelid, indkey, indisclustered,
indisvalid, indisunique, indisprimary, n.nspname,indnatts,cls.reltablespace AS spcoid, indisvalid, indisunique, indisprimary, n.nspname,indnatts,cls.reltablespace AS spcoid,
COALESCE(spcname, 'pg_default') as spcname, tab.relname as tabname, indclass, con.oid AS conoid, CASE WHEN length(spcname) > 0 THEN spcname ELSE
(SELECT sp.spcname FROM pg_database dtb
JOIN pg_tablespace sp ON dtb.dattablespace=sp.oid
WHERE dtb.oid = {{ did }}::oid)
END as spcname,
tab.relname as tabname, indclass, con.oid AS conoid,
CASE WHEN contype IN ('p', 'u', 'x') THEN desp.description CASE WHEN contype IN ('p', 'u', 'x') THEN desp.description
ELSE des.description END AS description, ELSE des.description END AS description,
pg_get_expr(indpred, indrelid, true) as indconstraint, contype, condeferrable, condeferred, amname, pg_get_expr(indpred, indrelid, true) as indconstraint, contype, condeferrable, condeferred, amname,

View File

@ -1,7 +1,11 @@
SELECT cls.oid, SELECT cls.oid,
cls.relname as name, cls.relname as name,
indnatts, indnatts,
COALESCE(spcname, 'pg_default') as spcname, CASE WHEN length(spcname) > 0 THEN spcname ELSE
(SELECT sp.spcname FROM pg_database dtb
JOIN pg_tablespace sp ON dtb.dattablespace=sp.oid
WHERE dtb.oid = {{ did }}::oid)
END as spcname,
CASE contype CASE contype
WHEN 'p' THEN desp.description WHEN 'p' THEN desp.description
WHEN 'u' THEN desp.description WHEN 'u' THEN desp.description

View File

@ -253,7 +253,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
name: undefined, name: undefined,
oid: undefined, oid: undefined,
spcoid: undefined, spcoid: undefined,
spcname: 'pg_default', spcname: undefined,
relowner: undefined, relowner: undefined,
relacl: undefined, relacl: undefined,
relhasoids: undefined, relhasoids: undefined,
@ -315,7 +315,7 @@ function($, _, S, pgAdmin, pgBrowser, alertify) {
},{ },{
id: 'spcname', label:'{{ _('Tablespace') }}', node: 'tablespace', id: 'spcname', label:'{{ _('Tablespace') }}', node: 'tablespace',
type: 'text', control: 'node-list-by-name', disabled: 'inSchema', type: 'text', control: 'node-list-by-name', disabled: 'inSchema',
mode: ['properties', 'create', 'edit'], select2:{allowClear:false}, mode: ['properties', 'create', 'edit'],
filter: function(d) { filter: function(d) {
// If tablespace name is not "pg_global" then we need to exclude them // If tablespace name is not "pg_global" then we need to exclude them
return (!(d && d.label.match(/pg_global/))) return (!(d && d.label.match(/pg_global/)))

View File

@ -79,10 +79,12 @@ WITH (
toast.{{opt.name}} = {{opt.value}}{% endif %} toast.{{opt.name}} = {{opt.value}}{% endif %}
{% endfor %}{% endif %} {% endfor %}{% endif %}
)
{### SQL for Tablespace ###} {### SQL for Tablespace ###}
{% if data.spcname %} {% if data.spcname %}
)
TABLESPACE {{ conn|qtIdent(data.spcname) }}; TABLESPACE {{ conn|qtIdent(data.spcname) }};
{% else %}
);
{% endif %} {% endif %}
{### Alter SQL for Owner ###} {### Alter SQL for Owner ###}
{% if data.relowner %} {% if data.relowner %}

View File

@ -1,5 +1,9 @@
SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS relacl_str, SELECT rel.oid, rel.relname AS name, rel.reltablespace AS spcoid,rel.relacl AS relacl_str,
(CASE WHEN length(spc.spcname) > 0 THEN spc.spcname ELSE 'pg_default' END) as spcname, (CASE WHEN length(spc.spcname) > 0 THEN spc.spcname ELSE
(SELECT sp.spcname FROM pg_database dtb
JOIN pg_tablespace sp ON dtb.dattablespace=sp.oid
WHERE dtb.oid = {{ did }}::oid)
END) as spcname,
(select nspname FROM pg_namespace WHERE oid = {{scid}}::oid ) as schema, (select nspname FROM pg_namespace WHERE oid = {{scid}}::oid ) as schema,
pg_get_userbyid(rel.relowner) AS relowner, rel.relhasoids, pg_get_userbyid(rel.relowner) AS relowner, rel.relhasoids,
rel.relhassubclass, rel.reltuples, des.description, con.conname, con.conkey, rel.relhassubclass, rel.reltuples, des.description, con.conname, con.conkey,

View File

@ -320,7 +320,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
Fetches all views properties and render into properties tab Fetches all views properties and render into properties tab
""" """
SQL = render_template("/".join( SQL = render_template("/".join(
[self.template_path, 'sql/properties.sql']), scid=scid) [self.template_path, 'sql/properties.sql']), did=did, scid=scid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
if not status: if not status:
@ -462,7 +462,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
) )
) )
try: try:
SQL, nameOrError = self.getSQL(gid, sid, data) SQL, nameOrError = self.getSQL(gid, sid, did, data)
if SQL is None: if SQL is None:
return nameOrError return nameOrError
SQL = SQL.strip('\n').strip(' ') SQL = SQL.strip('\n').strip(' ')
@ -506,7 +506,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
request.data, encoding='utf-8' request.data, encoding='utf-8'
) )
try: try:
SQL, nameOrError = self.getSQL(gid, sid, data, vid) SQL, nameOrError = self.getSQL(gid, sid, did, data, vid)
if SQL is None: if SQL is None:
return nameOrError return nameOrError
SQL = SQL.strip('\n').strip(' ') SQL = SQL.strip('\n').strip(' ')
@ -557,6 +557,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
"/".join([ "/".join([
self.template_path, 'sql/properties.sql' self.template_path, 'sql/properties.sql'
]), ]),
did=did,
vid=vid, vid=vid,
datlastsysoid=self.datlastsysoid datlastsysoid=self.datlastsysoid
) )
@ -631,7 +632,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
except ValueError: except ValueError:
data[k] = v data[k] = v
sql, nameOrError = self.getSQL(gid, sid, data, vid) sql, nameOrError = self.getSQL(gid, sid, did, data, vid)
if sql is None: if sql is None:
return nameOrError return nameOrError
@ -645,7 +646,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
status=200 status=200
) )
def getSQL(self, gid, sid, data, vid=None): def getSQL(self, gid, sid, did, data, vid=None):
""" """
This function will generate sql from model data This function will generate sql from model data
""" """
@ -901,7 +902,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
return SQL_data return SQL_data
def get_index_sql(self, vid): def get_index_sql(self, did, vid):
""" """
Get all index associated with view node, Get all index associated with view node,
generate their sql and render generate their sql and render
@ -910,10 +911,12 @@ class ViewNode(PGChildNodeView, VacuumSettings):
self.index_temp_path = 'index' self.index_temp_path = 'index'
SQL_data = '' SQL_data = ''
SQL = render_template("/".join(
[self.index_temp_path, 'sql/#{0}#/properties.sql'.format(self.manager.version)]),
did=did,
tid=vid)
status, data = self.conn.execute_dict(SQL) status, data = self.conn.execute_dict(SQL)
if not status: if not status:
SQL = render_template("/".join(
[self.index_temp_path, 'sql/#{0}#/properties.sql'.format(self.manager.version)]), tid=vid)
return internal_server_error(errormsg=data) return internal_server_error(errormsg=data)
for index in data['rows']: for index in data['rows']:
@ -921,6 +924,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
SQL = render_template("/".join( SQL = render_template("/".join(
[self.index_temp_path, 'sql/#{0}#/properties.sql'.format(self.manager.version)]), [self.index_temp_path, 'sql/#{0}#/properties.sql'.format(self.manager.version)]),
idx=index['oid'], idx=index['oid'],
did=did,
tid=vid tid=vid
) )
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
@ -1007,7 +1011,7 @@ class ViewNode(PGChildNodeView, VacuumSettings):
SQL_data += SQL SQL_data += SQL
SQL_data += self.get_rule_sql(vid) SQL_data += self.get_rule_sql(vid)
SQL_data += self.get_trigger_sql(vid) SQL_data += self.get_trigger_sql(vid)
SQL_data += self.get_index_sql(vid) SQL_data += self.get_index_sql(did, vid)
return ajax_response(response=SQL_data) return ajax_response(response=SQL_data)
@ -1259,13 +1263,14 @@ class MViewNode(ViewNode, VacuumSettings):
'9.3_plus' '9.3_plus'
) )
def getSQL(self, gid, sid, data, vid=None): def getSQL(self, gid, sid, did, data, vid=None):
""" """
This function will generate sql from model data This function will generate sql from model data
""" """
if vid is not None: if vid is not None:
SQL = render_template("/".join( SQL = render_template("/".join(
[self.template_path, 'sql/properties.sql']), [self.template_path, 'sql/properties.sql']),
did=did,
vid=vid, vid=vid,
datlastsysoid=self.datlastsysoid datlastsysoid=self.datlastsysoid
) )
@ -1452,6 +1457,7 @@ class MViewNode(ViewNode, VacuumSettings):
SQL_data = '' SQL_data = ''
SQL = render_template("/".join( SQL = render_template("/".join(
[self.template_path, 'sql/properties.sql']), [self.template_path, 'sql/properties.sql']),
did=did,
vid=vid, vid=vid,
datlastsysoid=self.datlastsysoid datlastsysoid=self.datlastsysoid
) )
@ -1530,7 +1536,7 @@ class MViewNode(ViewNode, VacuumSettings):
SQL_data += SQL SQL_data += SQL
SQL_data += self.get_rule_sql(vid) SQL_data += self.get_rule_sql(vid)
SQL_data += self.get_trigger_sql(vid) SQL_data += self.get_trigger_sql(vid)
SQL_data += self.get_index_sql(vid) SQL_data += self.get_index_sql(did, vid)
SQL_data = SQL_data.strip('\n') SQL_data = SQL_data.strip('\n')
return ajax_response(response=SQL_data) return ajax_response(response=SQL_data)
@ -1576,7 +1582,7 @@ class MViewNode(ViewNode, VacuumSettings):
""" """
SQL = render_template("/".join( SQL = render_template("/".join(
[self.template_path, 'sql/properties.sql'] [self.template_path, 'sql/properties.sql']
), vid=vid, datlastsysoid=self.datlastsysoid) ), did=did, vid=vid, datlastsysoid=self.datlastsysoid)
status, res = self.conn.execute_dict(SQL) status, res = self.conn.execute_dict(SQL)
if not status: if not status:
return internal_server_error(errormsg=res) return internal_server_error(errormsg=res)

View File

@ -126,7 +126,7 @@ function($, _, S, pgAdmin, alertify, pgBrowser, CodeMirror) {
pgBrowser.Node.Model.prototype.initialize.apply(this, arguments); pgBrowser.Node.Model.prototype.initialize.apply(this, arguments);
}, },
defaults: { defaults: {
spcname: 'pg_default', spcname: undefined,
toast_autovacuum_enabled: false, toast_autovacuum_enabled: false,
autovacuum_enabled: false autovacuum_enabled: false
}, },

View File

@ -6,7 +6,11 @@ SELECT
c.relname AS name, c.relname AS name,
c.reltablespace AS spcoid, c.reltablespace AS spcoid,
c.relispopulated AS with_data, c.relispopulated AS with_data,
(CASE WHEN length(spc.spcname) > 0 THEN spc.spcname ELSE 'pg_default' END) as spcname, CASE WHEN length(spcname) > 0 THEN spcname ELSE
(SELECT sp.spcname FROM pg_database dtb
JOIN pg_tablespace sp ON dtb.dattablespace=sp.oid
WHERE dtb.oid = {{ did }}::oid)
END as spcname,
c.relacl, c.relacl,
nsp.nspname as schema, nsp.nspname as schema,
pg_get_userbyid(c.relowner) AS owner, pg_get_userbyid(c.relowner) AS owner,

View File

@ -6,7 +6,11 @@ SELECT
c.relname AS name, c.relname AS name,
c.reltablespace AS spcoid, c.reltablespace AS spcoid,
c.relispopulated AS with_data, c.relispopulated AS with_data,
(CASE WHEN length(spc.spcname) > 0 THEN spc.spcname ELSE 'pg_default' END) as spcname, CASE WHEN length(spcname) > 0 THEN spcname ELSE
(SELECT sp.spcname FROM pg_database dtb
JOIN pg_tablespace sp ON dtb.dattablespace=sp.oid
WHERE dtb.oid = {{ did }}::oid)
END as spcname,
c.relacl, c.relacl,
nsp.nspname as schema, nsp.nspname as schema,
pg_get_userbyid(c.relowner) AS owner, pg_get_userbyid(c.relowner) AS owner,

View File

@ -6,7 +6,11 @@ SELECT
c.relname AS name, c.relname AS name,
c.reltablespace AS spcoid, c.reltablespace AS spcoid,
c.relispopulated AS with_data, c.relispopulated AS with_data,
(CASE WHEN length(spc.spcname) > 0 THEN spc.spcname ELSE 'pg_default' END) as spcname, CASE WHEN length(spcname) > 0 THEN spcname ELSE
(SELECT sp.spcname FROM pg_database dtb
JOIN pg_tablespace sp ON dtb.dattablespace=sp.oid
WHERE dtb.oid = {{ did }}::oid)
END as spcname,
c.relacl, c.relacl,
nsp.nspname as schema, nsp.nspname as schema,
pg_get_userbyid(c.relowner) AS owner, pg_get_userbyid(c.relowner) AS owner,