Add proper ORM and postgres support (#3978)

* Add postgresql support

* Fixes

* Fix perfs
This commit is contained in:
Charles Bochet
2024-02-14 17:53:50 +01:00
committed by GitHub
parent 94ad0e33ec
commit 4613f64910
24 changed files with 2143 additions and 344 deletions

View File

@ -0,0 +1,14 @@
import { Config } from 'drizzle-kit';
import 'dotenv/config';
const sqliteConfig = {
schema: './src/database/sqlite/schema-sqlite.ts',
out: './src/database/sqlite/migrations',
driver: 'libsql',
dbCredentials: {
url: 'twenty-website.sqlite',
},
} satisfies Config;
export default sqliteConfig;

View File

@ -0,0 +1,54 @@
CREATE TABLE `issueLabels` (
`issueId` text,
`labelId` text,
FOREIGN KEY (`issueId`) REFERENCES `issues`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`labelId`) REFERENCES `labels`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `issues` (
`id` text PRIMARY KEY NOT NULL,
`externalId` text,
`title` text,
`body` text,
`url` text,
`createdAt` text,
`updatedAt` text,
`closedAt` text,
`authorId` text,
FOREIGN KEY (`authorId`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `labels` (
`id` text PRIMARY KEY NOT NULL,
`externalId` text,
`name` text,
`color` text,
`description` text
);
--> statement-breakpoint
CREATE TABLE `pullRequestLabels` (
`pullRequestExternalId` text,
`labelId` text,
FOREIGN KEY (`pullRequestExternalId`) REFERENCES `pullRequests`(`id`) ON UPDATE no action ON DELETE no action,
FOREIGN KEY (`labelId`) REFERENCES `labels`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `pullRequests` (
`id` text PRIMARY KEY NOT NULL,
`title` text,
`body` text,
`url` text,
`createdAt` text,
`updatedAt` text,
`closedAt` text,
`mergedAt` text,
`authorId` text,
FOREIGN KEY (`authorId`) REFERENCES `users`(`id`) ON UPDATE no action ON DELETE no action
);
--> statement-breakpoint
CREATE TABLE `users` (
`id` text PRIMARY KEY NOT NULL,
`avatarUrl` text,
`url` text,
`isEmployee` text
);

View File

@ -0,0 +1,367 @@
{
"version": "5",
"dialect": "sqlite",
"id": "033cd768-53b9-4c60-99ee-be070ea7abd6",
"prevId": "00000000-0000-0000-0000-000000000000",
"tables": {
"issueLabels": {
"name": "issueLabels",
"columns": {
"issueId": {
"name": "issueId",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"labelId": {
"name": "labelId",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"issueLabels_issueId_issues_id_fk": {
"name": "issueLabels_issueId_issues_id_fk",
"tableFrom": "issueLabels",
"tableTo": "issues",
"columnsFrom": [
"issueId"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"issueLabels_labelId_labels_id_fk": {
"name": "issueLabels_labelId_labels_id_fk",
"tableFrom": "issueLabels",
"tableTo": "labels",
"columnsFrom": [
"labelId"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"issues": {
"name": "issues",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"externalId": {
"name": "externalId",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"body": {
"name": "body",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"url": {
"name": "url",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"updatedAt": {
"name": "updatedAt",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"closedAt": {
"name": "closedAt",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"authorId": {
"name": "authorId",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"issues_authorId_users_id_fk": {
"name": "issues_authorId_users_id_fk",
"tableFrom": "issues",
"tableTo": "users",
"columnsFrom": [
"authorId"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"labels": {
"name": "labels",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"externalId": {
"name": "externalId",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"name": {
"name": "name",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"color": {
"name": "color",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"description": {
"name": "description",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"pullRequestLabels": {
"name": "pullRequestLabels",
"columns": {
"pullRequestExternalId": {
"name": "pullRequestExternalId",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"labelId": {
"name": "labelId",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"pullRequestLabels_pullRequestExternalId_pullRequests_id_fk": {
"name": "pullRequestLabels_pullRequestExternalId_pullRequests_id_fk",
"tableFrom": "pullRequestLabels",
"tableTo": "pullRequests",
"columnsFrom": [
"pullRequestExternalId"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
},
"pullRequestLabels_labelId_labels_id_fk": {
"name": "pullRequestLabels_labelId_labels_id_fk",
"tableFrom": "pullRequestLabels",
"tableTo": "labels",
"columnsFrom": [
"labelId"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"pullRequests": {
"name": "pullRequests",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"title": {
"name": "title",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"body": {
"name": "body",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"url": {
"name": "url",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"createdAt": {
"name": "createdAt",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"updatedAt": {
"name": "updatedAt",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"closedAt": {
"name": "closedAt",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"mergedAt": {
"name": "mergedAt",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"authorId": {
"name": "authorId",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {
"pullRequests_authorId_users_id_fk": {
"name": "pullRequests_authorId_users_id_fk",
"tableFrom": "pullRequests",
"tableTo": "users",
"columnsFrom": [
"authorId"
],
"columnsTo": [
"id"
],
"onDelete": "no action",
"onUpdate": "no action"
}
},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
},
"users": {
"name": "users",
"columns": {
"id": {
"name": "id",
"type": "text",
"primaryKey": true,
"notNull": true,
"autoincrement": false
},
"avatarUrl": {
"name": "avatarUrl",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"url": {
"name": "url",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
},
"isEmployee": {
"name": "isEmployee",
"type": "text",
"primaryKey": false,
"notNull": false,
"autoincrement": false
}
},
"indexes": {},
"foreignKeys": {},
"compositePrimaryKeys": {},
"uniqueConstraints": {}
}
},
"enums": {},
"_meta": {
"schemas": {},
"tables": {},
"columns": {}
}
}

View File

@ -0,0 +1,13 @@
{
"version": "5",
"dialect": "sqlite",
"entries": [
{
"idx": 0,
"version": "5",
"when": 1707920913359,
"tag": "0000_small_karma",
"breakpoints": true
}
]
}

View File

@ -0,0 +1,52 @@
import { sqliteTable, text } from 'drizzle-orm/sqlite-core';
export const sqlLiteUsers = sqliteTable('users', {
id: text('id').primaryKey(),
avatarUrl: text('avatarUrl'),
url: text('url'),
isEmployee: text('isEmployee'),
});
export const sqlLitePullRequests = sqliteTable('pullRequests', {
id: text('id').primaryKey(),
name: text('title'),
body: text('body'),
url: text('url'),
createdAt: text('createdAt'),
updatedAt: text('updatedAt'),
closedAt: text('closedAt'),
mergedAt: text('mergedAt'),
authorId: text('authorId').references(() => sqlLiteUsers.id),
});
export const sqlLiteIssues = sqliteTable('issues', {
id: text('id').primaryKey(),
externalId: text('externalId'),
title: text('title'),
body: text('body'),
url: text('url'),
createdAt: text('createdAt'),
updatedAt: text('updatedAt'),
closedAt: text('closedAt'),
authorId: text('authorId').references(() => sqlLiteUsers.id),
});
export const sqlLiteLabels = sqliteTable('labels', {
id: text('id').primaryKey(),
externalId: text('externalId'),
name: text('name'),
color: text('color'),
description: text('description'),
});
export const sqlLitePullRequestLabels = sqliteTable('pullRequestLabels', {
pullRequestId: text('pullRequestExternalId').references(
() => sqlLitePullRequests.id,
),
labelId: text('labelId').references(() => sqlLiteLabels.id),
});
export const sqlLiteIssueLabels = sqliteTable('issueLabels', {
issueId: text('issueId').references(() => sqlLiteIssues.id),
labelId: text('labelId').references(() => sqlLiteLabels.id),
});