entc/gen: initial work for multi-schema migration using atlasgo.io (#3821)

This commit is contained in:
Ariel Mashraki
2023-11-13 12:35:31 +02:00
committed by GitHub
parent 50938a51c6
commit 9aba4ae091
116 changed files with 15265 additions and 203 deletions

View File

@@ -192,3 +192,29 @@ func NewSchemaConfigContext(parent context.Context, config SchemaConfig) context
{{- end }}
step.Edge.Schema = schemaConfig.{{ $schema }}
{{- end -}}
{{- define "config/init/fields/multischema" }}
{{- if $.FeatureEnabled "sql/multischema" }}
cfg.schemaConfig = DefaultSchemaConfig
{{- end }}
{{- end }}
{{- define "dialect/sql/config/options/multischema" }}
{{- if $.FeatureEnabled "sql/multischema" }}
{{- $all := $.TableSchemas }}
var (
// DefaultSchemaConfig represents the default schema names for all tables as defined in ent/schema.
DefaultSchemaConfig = SchemaConfig {
{{- range $n := $.Nodes }}
{{ $n.Name }}: tableSchemas[{{ indexOf $all $n.TableSchema }}],
{{- range $e := $n.Edges }}
{{- if and $e.M2M (not $e.Inverse) (not $e.Through) }}
{{ $n.Name }}{{ $e.StructField }}: tableSchemas[{{ indexOf $all $e.TableSchema }}],
{{- end }}
{{- end }}
{{- end }}
}
tableSchemas = [...]string{ {{- range $i, $s := $all }}{{ if $i }},{{ end }}"{{ $s }}"{{ end }} }
)
{{- end }}
{{- end }}

View File

@@ -34,6 +34,11 @@ in the LICENSE file in the root directory of this source tree.
{{ $e.ColumnConstant }} = "{{ $e.Rel.Column }}"
{{- end }}
{{- end }}
{{- with $tmpls := matchTemplate "dialect/sql/meta/constants/*" }}
{{- range $tmpl := $tmpls }}
{{- xtemplate $tmpl $ }}
{{- end }}
{{- end }}
{{ end }}
{{/* Variables needed for sql dialects. */}}