Closed kazhuravlev closed 11 months ago
Hi @kazhuravlev. It is possible to change destination directories using Generator Customization, check these tests for more details: TestGeneratorTemplate_Schema_ChangePath, TestGeneratorTemplate_Model_ChangePath and TestGeneratorTemplate_SQLBuilder_ChangePath.
Of course I can manage the base directory. But I can't manage the rest of the directories (after the specified one).
When I set the resulting directory like ./output
, I get a result like ./output/<DBNAME>/<SCHEMA_NAME>
. But in my case there are multiple databases with different schemas inside each. So I don't want to have additional directories after ./output
. Only ./output/[model|table]
(instead of ./output/some__database_name/some__schema_name/[model|table]
).
Initial problem - I have local databases (dev dbs) and multiple databases in production. Each database is a separate tenant (client) with the same schema but different data. After generating, I get a little strange code, which contains the name of the database.
Main argument: The database name is only a configuration option and must be controlled by the jet user. Ideally, the schema name is the same.
To remove database name, you can use relative path "../"
.
err := postgres.Generate( // or GenerateDSN
"./output",
dbConnection,
template.Default(postgres2.Dialect).
UseSchema(func(schemaMetaData metadata.Schema) template.Schema {
return template.DefaultSchema(schemaMetaData).UsePath("../")
}),
)
Now generator will generate to ./output/[model|table|enum]
folders.
Thanks, solved!
Problem We would like to control the destination directory of
postgres.GenerateDSN
, but inside this function we have a hardcoded value - the database name and schema path.Desired solution I see several options:
GenerateDSN
(backward compatibility issue)GenerateDSN
with functional options for this and other changes (as in Dave Cheney's article). I can recommend this toolgenerator/postgres.postgresQuerySet
asDefaultQuerySet() metadata.DialectQuerySet
For our case, we would like to have the second option, hiding the complexity of the generator implementation.