Browse Source

refactor: use f-strings instead of .format and %

version-14
Ankush Menat 3 years ago
parent
commit
33890ed860
1 changed files with 12 additions and 10 deletions
  1. +12
    -10
      frappe/database/postgres/schema.py

+ 12
- 10
frappe/database/postgres/schema.py View File

@@ -5,29 +5,29 @@ from frappe.database.schema import DBTable, get_definition


class PostgresTable(DBTable): class PostgresTable(DBTable):
def create(self): def create(self):
add_text = ""
varchar_len = frappe.db.VARCHAR_LEN


additional_definitions = ""
# columns # columns
column_defs = self.get_column_definitions() column_defs = self.get_column_definitions()
if column_defs: if column_defs:
add_text += ",\n".join(column_defs)
additional_definitions += ",\n".join(column_defs)


# child table columns # child table columns
if self.meta.get("istable") or 0: if self.meta.get("istable") or 0:
if column_defs: if column_defs:
add_text += ",\n"
additional_definitions += ",\n"


add_text += ",\n".join(
additional_definitions += ",\n".join(
( (
"parent varchar({varchar_len})".format(varchar_len=frappe.db.VARCHAR_LEN),
"parentfield varchar({varchar_len})".format(varchar_len=frappe.db.VARCHAR_LEN),
"parenttype varchar({varchar_len})".format(varchar_len=frappe.db.VARCHAR_LEN)
f"parent varchar({varchar_len})",
f"parentfield varchar({varchar_len})",
f"parenttype varchar({varchar_len})",
) )
) )


# TODO: set docstatus length
# create table # create table
frappe.db.sql("""create table `%s` (
frappe.db.sql(f"""create table `{self.table_name}` (
name varchar({varchar_len}) not null primary key, name varchar({varchar_len}) not null primary key,
creation timestamp(6), creation timestamp(6),
modified timestamp(6), modified timestamp(6),
@@ -35,7 +35,9 @@ class PostgresTable(DBTable):
owner varchar({varchar_len}), owner varchar({varchar_len}),
docstatus smallint not null default '0', docstatus smallint not null default '0',
idx bigint not null default '0', idx bigint not null default '0',
%s)""".format(varchar_len=frappe.db.VARCHAR_LEN) % (self.table_name, add_text))
{additional_definitions}
)"""
)


self.create_indexes() self.create_indexes()
frappe.db.commit() frappe.db.commit()


Loading…
Cancel
Save