mirror of
https://github.com/Unleash/unleash.git
synced 2025-05-03 01:18:43 +02:00
feat: add support for handling non standard postgres dates (#1689)
* feat: add support for handling non standard postgres dates * docs: update some http docs links to point to their respective https versions * chore: refactor non standard date handling callback code to be a little clearer * Update website/docs/deploy/configuring-unleash-v3.md Co-authored-by: Thomas Heartman <thomas@getunleash.ai> Co-authored-by: Thomas Heartman <thomas@getunleash.ai>
This commit is contained in:
parent
919861eb9f
commit
18e63d5ea3
@ -91,6 +91,12 @@ function loadUI(options: IUnleashOptions): IUIConfig {
|
||||
return mergeAll([uiO, ui]);
|
||||
}
|
||||
|
||||
const dateHandlingCallback = (connection, callback) => {
|
||||
connection.query("set datestyle to 'ISO, DMY';", (err: any) => {
|
||||
callback(err, connection);
|
||||
});
|
||||
};
|
||||
|
||||
const defaultDbOptions: IDBOption = {
|
||||
user: process.env.DATABASE_USERNAME,
|
||||
password: process.env.DATABASE_PASSWORD,
|
||||
@ -111,6 +117,9 @@ const defaultDbOptions: IDBOption = {
|
||||
process.env.DATABASE_POOL_IDLE_TIMEOUT_MS,
|
||||
secondsToMilliseconds(30),
|
||||
),
|
||||
...(parseEnvVarBoolean(process.env.ALLOW_NON_STANDARD_DB_DATES, false)
|
||||
? { afterCreate: dateHandlingCallback }
|
||||
: {}),
|
||||
propagateCreateError: false,
|
||||
},
|
||||
schema: process.env.DATABASE_SCHEMA || 'public',
|
||||
|
@ -28,6 +28,7 @@ export interface IDBOption {
|
||||
max?: number;
|
||||
idleTimeoutMillis?: number;
|
||||
propagateCreateError?: boolean;
|
||||
afterCreate?: (connection: any, callback: any) => void;
|
||||
};
|
||||
schema: string;
|
||||
disableMigration: boolean;
|
||||
|
@ -40,10 +40,11 @@ unleash.start(unleashOptions);
|
||||
- _database_ - the database name to be used (`DATABASE_NAME`)
|
||||
- _ssl_ - an object describing ssl options, see https://node-postgres.com/features/ssl (`DATABASE_SSL`, as a stringified json object)
|
||||
- _version_ - the postgres database version. Used to connect a non-standard database. Defaults to `undefined`, which let the underlying adapter to detect the version automatically. (`DATABASE_VERSION`)
|
||||
- _pool_ - an object describing pool options, see https://knexjs.org/#Installation-pooling. We support the following three fields:
|
||||
- _pool_ - an object describing pool options, see https://knexjs.org/guide/#pool. We support the following four fields:
|
||||
- _min_ - minimum connections in connections pool (defaults to 0) (`DATABASE_POOL_MIN`)
|
||||
- _max_ - maximum connections in connections pool (defaults to 4) (`DATABASE_POOL_MAX`)
|
||||
- _idleTimeoutMillis_ - time in milliseconds a connection must be idle before being marked as a candidate for eviction (defaults to 30000) (`DATABASE_POOL_IDLE_TIMEOUT_MS`)
|
||||
- _afterCreate_ - a callback for for configuring active connections, see https://knexjs.org/guide/#aftercreate. This is incompatible with the `ALLOW_NON_STANDARD_DB_DATES` environment variable, which will override this property to support non-standard Postgres date formats. If you've set your Postgres instance to use a date style other than `ISO, DMY` then you'll need to set the `ALLOW_NON_STANDARD_DB_DATES` environment variable to `true`. Setting the environment variable should be preferred over writing your own callback.
|
||||
- **databaseUrl** - (_deprecated_) the postgres database url to connect to. Only used if _db_ object is not specified, and overrides the _db_ object and any environment variables that change parts of it (like `DATABASE_SSL`). Should include username/password. This value may also be set via the `DATABASE_URL` environment variable. Alternatively, if you would like to read the database url from a file, you may set the `DATABASE_URL_FILE` environment variable with the full file path. The contents of the file must be the database url exactly.
|
||||
- **databaseSchema** - the postgres database schema to use. Defaults to 'public'. (`DATABASE_SCHEMA`)
|
||||
- **port** - which port the unleash-server should bind to. If port is omitted or is 0, the operating system will assign an arbitrary unused port. Will be ignored if pipe is specified. This value may also be set via the `HTTP_PORT` environment variable
|
||||
@ -80,7 +81,7 @@ unleash
|
||||
databaseUrl: 'postgres://unleash_user:password@localhost:5432/unleash',
|
||||
port: 4242,
|
||||
})
|
||||
.then(result => {
|
||||
.then((result) => {
|
||||
app.use(result.app);
|
||||
console.log(`Unleash app generated and attached to parent application`);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user