Kaynağa Gözat

Merge pull request #16067 from cpdeethree/postgres-fix-table-creation

fix: error in table creation from incorrect scope
version-14
Ankush Menat 3 yıl önce
committed by GitHub
ebeveyn
işleme
2580561788
Veri tabanında bu imza için bilinen anahtar bulunamadı GPG Anahtar Kimliği: 4AEE18F83AFDEB23
2 değiştirilmiş dosya ile 19 ekleme ve 10 silme
  1. +7
    -0
      frappe/core/doctype/doctype/test_doctype.py
  2. +12
    -10
      frappe/database/postgres/schema.py

+ 7
- 0
frappe/core/doctype/doctype/test_doctype.py Dosyayı Görüntüle

@@ -498,6 +498,13 @@ class TestDocType(unittest.TestCase):
self.assertEqual(doc.is_virtual, 1) self.assertEqual(doc.is_virtual, 1)
self.assertFalse(frappe.db.table_exists('Test Virtual Doctype')) self.assertFalse(frappe.db.table_exists('Test Virtual Doctype'))


def test_default_fieldname(self):
fields = [{"label": "title", "fieldname": "title", "fieldtype": "Data", "default": "{some_fieldname}"}]
dt = new_doctype("DT with default field", fields=fields)
dt.insert()

dt.delete()

def new_doctype(name, unique=0, depends_on='', fields=None): def new_doctype(name, unique=0, depends_on='', fields=None):
doc = frappe.get_doc({ doc = frappe.get_doc({
"doctype": "DocType", "doctype": "DocType",


+ 12
- 10
frappe/database/postgres/schema.py Dosyayı Görüntüle

@@ -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})",
"parentfield varchar({varchar_len})",
"parenttype varchar({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)""" % (self.table_name, add_text)).format(varchar_len=frappe.db.VARCHAR_LEN))
{additional_definitions}
)"""
)


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


Yükleniyor…
İptal
Kaydet