Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgres Default Values #842

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions schema/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ type Table struct {
Id string
}

// DefaultValue represents whether Defaultvalue is present, DefaultValue and IsSpannerSupported.
type DefaultValue struct {
IsPresent bool
DefaultValue string
IsSpannerSupported bool
}

// Column represents a database column.
// TODO: add support for foreign keys.
type Column struct {
Expand All @@ -52,6 +59,7 @@ type Column struct {
NotNull bool
Ignored Ignored
Id string
Default DefaultValue
}

// ForeignKey represents a foreign key.
Expand Down
9 changes: 9 additions & 0 deletions sources/postgres/infoschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,21 @@ func (isi InfoSchemaImpl) GetColumns(conv *internal.Conv, table common.SchemaAnd
}
ignored.Default = colDefault.Valid
colId := internal.GenerateColumnId()
defaultVal := schema.DefaultValue{
IsPresent: colDefault.Valid,
DefaultValue: "",
IsSpannerSupported: false,
}
if colDefault.Valid {
defaultVal.DefaultValue = colDefault.String
}
c := schema.Column{
Id: colId,
Name: colName,
Type: toType(dataType, elementDataType, charMaxLen, numericPrecision, numericScale),
NotNull: common.ToNotNull(conv, isNullable),
Ignored: ignored,
Default: defaultVal,
}
colDefs[colId] = c
colIds = append(colIds, colId)
Expand Down
Loading