Files
twenty/packages/twenty-website/src/database/database.ts
Ady Beraud df5cb9a904 Smart changelog (#5205)
Added a smart Changelog :

- Publish the Changelog before the app release. If the release has not
yet been pushed to production, do not display it.
- When the app release is done, make the Changelog available with the
correct date.
- If the Changelog writing is delayed because the release has already
been made, publish it immediately.
- Display everything locally to be able to iterate on the changelog and
have a preview

Added an endpoint for the Changelog

---------

Co-authored-by: Ady Beraud <a.beraud96@gmail.com>
Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
2024-05-01 08:35:11 +02:00

64 lines
1.5 KiB
TypeScript

import { global } from '@apollo/client/utilities/globals';
import { drizzle, PostgresJsDatabase } from 'drizzle-orm/postgres-js';
import { migrate as postgresMigrate } from 'drizzle-orm/postgres-js/migrator';
import postgres from 'postgres';
import 'dotenv/config';
let pgDb: PostgresJsDatabase;
if (global.process.env.DATABASE_PG_URL) {
const pgClient = postgres(`${global.process.env.DATABASE_PG_URL}`);
pgDb = drizzle(pgClient, { logger: false });
}
const migrate = async () => {
await postgresMigrate(pgDb, {
migrationsFolder: './src/database/migrations',
});
};
const findOne = (model: any, orderBy: any) => {
return pgDb.select().from(model).orderBy(orderBy).limit(1).execute();
};
const findAll = (model: any, orderBy?: any) => {
if (orderBy) {
return pgDb.select().from(model).orderBy(orderBy).execute();
}
return pgDb.select().from(model).execute();
};
const insertMany = async (
model: any,
data: any,
options?: {
onConflictKey?: string;
onConflictUpdateObject?: any;
},
) => {
const query = pgDb.insert(model).values(data);
if (options?.onConflictUpdateObject) {
if (options?.onConflictKey) {
return query
.onConflictDoUpdate({
target: [model[options.onConflictKey]],
set: options.onConflictUpdateObject,
})
.execute();
}
}
if (options?.onConflictKey) {
return query
.onConflictDoNothing({
target: [model[options.onConflictKey]],
})
.execute();
}
return query.execute();
};
export { findAll, findOne, insertMany, migrate };