(out io.Writer, schema string, table *storepb.TableMetadata, sequences []*storepb.SequenceMetadata)
| 1710 | } |
| 1711 | |
| 1712 | func writeTable(out io.Writer, schema string, table *storepb.TableMetadata, sequences []*storepb.SequenceMetadata) error { |
| 1713 | if tableMissingColumnMetadata(table) { |
| 1714 | // Emit a bare CREATE TABLE so the table still exists on replay, and |
| 1715 | // skip constraints, indexes, partitions, and sequence ownership — |
| 1716 | // they all reference columns absent from the dump. |
| 1717 | if err := writeCreateTable(out, schema, table.Name, nil, nil, nil); err != nil { |
| 1718 | return err |
| 1719 | } |
| 1720 | if _, err := io.WriteString(out, ";\n\n"); err != nil { |
| 1721 | return err |
| 1722 | } |
| 1723 | if len(table.Comment) > 0 { |
| 1724 | return writeTableComment(out, schema, table) |
| 1725 | } |
| 1726 | return nil |
| 1727 | } |
| 1728 | |
| 1729 | generationTypes, identitySequences, nonIdentitySequences := splitSequencesByIdentityOrNot(table, sequences) |
| 1730 | |
| 1731 | if err := writeCreateTable(out, schema, table.Name, table.Columns, table.CheckConstraints, table.ExcludeConstraints); err != nil { |
| 1732 | return err |
| 1733 | } |
| 1734 | |
| 1735 | if len(table.Partitions) > 0 { |
| 1736 | if err := writePartitionClause(out, table.Partitions[0]); err != nil { |
| 1737 | return err |
| 1738 | } |
| 1739 | } |
| 1740 | |
| 1741 | if _, err := io.WriteString(out, ";\n\n"); err != nil { |
| 1742 | return err |
| 1743 | } |
| 1744 | |
| 1745 | // Skip OWNED BY for a table with no columns; the clause would reference |
| 1746 | // a column absent from the dump. |
| 1747 | if !tableHasNoColumns(table) { |
| 1748 | for _, sequence := range nonIdentitySequences { |
| 1749 | if err := writeAlterSequenceOwnedBy(out, schema, sequence); err != nil { |
| 1750 | return err |
| 1751 | } |
| 1752 | } |
| 1753 | } |
| 1754 | |
| 1755 | // Construct comments. |
| 1756 | if len(table.Comment) > 0 { |
| 1757 | if err := writeTableComment(out, schema, table); err != nil { |
| 1758 | return err |
| 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | for _, column := range table.Columns { |
| 1763 | if len(column.Comment) > 0 { |
| 1764 | if err := writeColumnComment(out, schema, table.Name, column); err != nil { |
| 1765 | return err |
| 1766 | } |
| 1767 | } |
| 1768 | } |
| 1769 |
no test coverage detected