diff --git a/backend/src/apis/humhub/HumHubClient.ts b/backend/src/apis/humhub/HumHubClient.ts index 3c6b2536f..59268cc9d 100644 --- a/backend/src/apis/humhub/HumHubClient.ts +++ b/backend/src/apis/humhub/HumHubClient.ts @@ -1,9 +1,8 @@ -import { ProjectBranding } from 'database' +import { dbFindProjectSpaceUrl } from 'database' import { SignJWT } from 'jose' import { getLogger } from 'log4js' import { IRequestOptions, IRestResponse, RestClient } from 'typed-rest-client' import { CONFIG } from '@/config' - import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const' import { LogError } from '@/server/LogError' import { PostUserLoggingView } from './logging/PostUserLogging.view' @@ -67,15 +66,9 @@ export class HumHubClient { public async createAutoLoginUrl(username: string, project?: string | null) { const secret = new TextEncoder().encode(CONFIG.HUMHUB_JWT_KEY) logger.info(`user ${username} as username for humhub auto-login`) - let redirectLink: string | undefined + let redirectLink: string | undefined | null if (project) { - const projectBranding = await ProjectBranding.findOne({ - where: { alias: project }, - select: { spaceUrl: true }, - }) - if (projectBranding?.spaceUrl) { - redirectLink = projectBranding.spaceUrl - } + redirectLink = await dbFindProjectSpaceUrl(project) } const token = await new SignJWT({ username, redirectLink }) .setProtectedHeader({ alg: 'HS256' }) diff --git a/backend/src/graphql/model/ProjectBranding.ts b/backend/src/graphql/model/ProjectBranding.ts index c879e918f..02984c62a 100644 --- a/backend/src/graphql/model/ProjectBranding.ts +++ b/backend/src/graphql/model/ProjectBranding.ts @@ -1,9 +1,10 @@ -import { ProjectBranding as dbProjectBranding } from 'database' +import { projectBrandingsTable } from 'database' import { Field, Int, ObjectType } from 'type-graphql' @ObjectType() export class ProjectBranding { - constructor(projectBranding: dbProjectBranding) { + // TODO: replace with valibot schema + constructor(projectBranding: typeof projectBrandingsTable.$inferSelect) { Object.assign(this, projectBranding) } diff --git a/backend/src/graphql/resolver/ProjectBrandingResolver.ts b/backend/src/graphql/resolver/ProjectBrandingResolver.ts index 610afa630..8e4a76c80 100644 --- a/backend/src/graphql/resolver/ProjectBrandingResolver.ts +++ b/backend/src/graphql/resolver/ProjectBrandingResolver.ts @@ -2,7 +2,13 @@ import { ProjectBrandingInput } from '@input/ProjectBrandingInput' import { ProjectBranding } from '@model/ProjectBranding' import { Space } from '@model/Space' import { SpaceList } from '@model/SpaceList' -import { ProjectBranding as DbProjectBranding } from 'database' +import { + dbDeleteProjectBranding, + dbFindAllProjectBrandings, + dbFindProjectBrandingById, + dbGetProjectLogoURL, + projectBrandingsTable +} from 'database' import { getLogger } from 'log4js' import { Arg, Authorized, ID, Int, Mutation, Query, Resolver } from 'type-graphql' import { HumHubClient } from '@/apis/humhub/HumHubClient' @@ -17,15 +23,15 @@ export class ProjectBrandingResolver { @Query(() => [ProjectBranding]) @Authorized([RIGHTS.PROJECT_BRANDING_VIEW]) async projectBrandings(): Promise { - return (await DbProjectBranding.find()).map( - (entity: DbProjectBranding) => new ProjectBranding(entity), + return (await dbFindAllProjectBrandings()).map( + (entity: typeof projectBrandingsTable.$inferSelect) => new ProjectBranding(entity), ) } @Query(() => ProjectBranding) @Authorized([RIGHTS.PROJECT_BRANDING_VIEW]) async projectBranding(@Arg('id', () => Int) id: number): Promise { - const projectBrandingEntity = await DbProjectBranding.findOneBy({ id }) + const projectBrandingEntity = await dbFindProjectBrandingById(id) if (!projectBrandingEntity) { throw new LogError(`Project Branding with id: ${id} not found`) } @@ -35,14 +41,7 @@ export class ProjectBrandingResolver { @Query(() => String, { nullable: true }) @Authorized([RIGHTS.PROJECT_BRANDING_BANNER]) async projectBrandingBanner(@Arg('alias', () => String) alias: string): Promise { - const projectBrandingEntity = await DbProjectBranding.findOne({ - where: { alias }, - select: { id: true, logoUrl: true }, - }) - if (!projectBrandingEntity) { - throw new LogError(`Project Branding with alias: ${alias} not found`) - } - return projectBrandingEntity.logoUrl + return await dbGetProjectLogoURL(alias) } @Mutation(() => ProjectBranding, { nullable: true }) @@ -64,7 +63,7 @@ export class ProjectBrandingResolver { @Authorized([RIGHTS.PROJECT_BRANDING_MUTATE]) async deleteProjectBranding(@Arg('id', () => ID) id: number): Promise { try { - await DbProjectBranding.delete({ id }) + await dbDeleteProjectBranding(id) return true } catch (err) { logger.error(err) diff --git a/database/drizzle/0000_unusual_the_order.sql b/database/drizzle/0000_unusual_the_order.sql new file mode 100644 index 000000000..843427f1b --- /dev/null +++ b/database/drizzle/0000_unusual_the_order.sql @@ -0,0 +1,303 @@ +-- Current sql file was generated after introspecting the database +-- If you want to run this migration please uncomment this code before executing migrations +/* +CREATE TABLE `communities` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `foreign` tinyint(4) NOT NULL DEFAULT 1, + `url` varchar(255) NOT NULL, + `public_key` binary(32) NOT NULL, + `private_key` binary(64) DEFAULT 'NULL', + `community_uuid` char(36) DEFAULT 'NULL', + `authenticated_at` datetime(3) DEFAULT 'NULL', + `name` varchar(40) DEFAULT 'NULL', + `description` varchar(255) DEFAULT 'NULL', + `gms_api_key` varchar(512) DEFAULT 'NULL', + `public_jwt_key` varchar(512) DEFAULT 'NULL', + `private_jwt_key` varchar(2048) DEFAULT 'NULL', + `location` geometry DEFAULT 'NULL', + `hiero_topic_id` varchar(512) DEFAULT 'NULL', + `creation_date` datetime(3) DEFAULT 'NULL', + `created_at` datetime(3) NOT NULL DEFAULT 'current_timestamp(3)', + `updated_at` datetime(3) DEFAULT 'NULL', + CONSTRAINT `url_key` UNIQUE(`url`), + CONSTRAINT `uuid_key` UNIQUE(`community_uuid`) +); +--> statement-breakpoint +CREATE TABLE `community_handshake_states` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `handshake_id` int(10) unsigned NOT NULL, + `one_time_code` int(10) unsigned DEFAULT 'NULL', + `public_key` binary(32) NOT NULL, + `api_version` varchar(255) NOT NULL, + `status` varchar(255) NOT NULL DEFAULT '''OPEN_CONNECTION''', + `last_error` text DEFAULT 'NULL', + `created_at` datetime(3) NOT NULL DEFAULT 'current_timestamp(3)', + `updated_at` datetime(3) NOT NULL DEFAULT 'current_timestamp(3)' +); +--> statement-breakpoint +CREATE TABLE `contributions` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `user_id` int(10) DEFAULT 'NULL', + `created_at` datetime DEFAULT 'NULL', + `resubmission_at` datetime DEFAULT 'NULL', + `contribution_date` datetime DEFAULT 'NULL', + `memo` varchar(512) NOT NULL, + `amount` decimal(40,20) NOT NULL, + `moderator_id` int(10) DEFAULT 'NULL', + `contribution_link_id` int(10) unsigned DEFAULT 'NULL', + `confirmed_by` int(10) unsigned DEFAULT 'NULL', + `confirmed_at` datetime DEFAULT 'NULL', + `denied_at` datetime DEFAULT 'NULL', + `denied_by` int(10) unsigned DEFAULT 'NULL', + `contribution_type` varchar(12) NOT NULL DEFAULT '''ADMIN''', + `contribution_status` varchar(12) NOT NULL DEFAULT '''PENDING''', + `deleted_at` datetime DEFAULT 'NULL', + `transaction_id` int(10) unsigned DEFAULT 'NULL', + `updated_at` datetime DEFAULT 'NULL', + `updated_by` int(10) unsigned DEFAULT 'NULL', + `deleted_by` int(10) unsigned DEFAULT 'NULL' +); +--> statement-breakpoint +CREATE TABLE `contribution_links` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `name` varchar(100) NOT NULL, + `memo` varchar(512) NOT NULL, + `valid_from` datetime NOT NULL, + `valid_to` datetime DEFAULT 'NULL', + `amount` bigint(20) NOT NULL, + `cycle` varchar(12) NOT NULL DEFAULT '''ONCE''', + `max_per_cycle` int(10) unsigned NOT NULL DEFAULT 1, + `max_amount_per_month` bigint(20) DEFAULT 'NULL', + `total_max_count_of_contribution` int(10) unsigned DEFAULT 'NULL', + `max_account_balance` bigint(20) DEFAULT 'NULL', + `min_gap_hours` int(10) unsigned DEFAULT 'NULL', + `created_at` datetime NOT NULL DEFAULT 'current_timestamp()', + `deleted_at` datetime DEFAULT 'NULL', + `code` varchar(24) NOT NULL, + `link_enabled` tinyint(4) NOT NULL DEFAULT 1 +); +--> statement-breakpoint +CREATE TABLE `contribution_messages` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `contribution_id` int(10) unsigned NOT NULL, + `user_id` int(10) unsigned NOT NULL, + `message` varchar(2000) NOT NULL, + `created_at` datetime NOT NULL DEFAULT 'current_timestamp()', + `updated_at` datetime DEFAULT 'NULL', + `deleted_at` datetime DEFAULT 'NULL', + `deleted_by` int(10) unsigned DEFAULT 'NULL', + `type` varchar(12) NOT NULL DEFAULT '''DIALOG''', + `is_moderator` tinyint(1) NOT NULL DEFAULT 0 +); +--> statement-breakpoint +CREATE TABLE `dlt_transactions` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `transaction_id` int(10) unsigned DEFAULT 'NULL', + `user_id` int(10) unsigned DEFAULT 'NULL', + `transaction_link_id` int(10) unsigned DEFAULT 'NULL', + `type_id` int(10) unsigned NOT NULL, + `message_id` varchar(64) DEFAULT 'NULL', + `verified` tinyint(4) NOT NULL DEFAULT 0, + `created_at` datetime(3) NOT NULL DEFAULT 'current_timestamp(3)', + `verified_at` datetime(3) DEFAULT 'NULL', + `error` text DEFAULT 'NULL' +); +--> statement-breakpoint +CREATE TABLE `events` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `type` varchar(100) NOT NULL, + `created_at` datetime(3) NOT NULL DEFAULT 'current_timestamp(3)', + `affected_user_id` int(10) unsigned NOT NULL, + `acting_user_id` int(10) unsigned NOT NULL, + `involved_user_id` int(10) unsigned DEFAULT 'NULL', + `involved_transaction_id` int(10) unsigned DEFAULT 'NULL', + `involved_contribution_id` int(10) unsigned DEFAULT 'NULL', + `involved_contribution_message_id` int(10) unsigned DEFAULT 'NULL', + `involved_transaction_link_id` int(10) unsigned DEFAULT 'NULL', + `involved_contribution_link_id` int(10) unsigned DEFAULT 'NULL', + `amount` bigint(20) DEFAULT 'NULL' +); +--> statement-breakpoint +CREATE TABLE `federated_communities` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `foreign` tinyint(4) NOT NULL DEFAULT 1, + `public_key` binary(32) NOT NULL, + `api_version` varchar(10) NOT NULL, + `end_point` varchar(255) NOT NULL, + `last_announced_at` datetime(3) DEFAULT 'NULL', + `verified_at` datetime(3) DEFAULT 'NULL', + `last_error_at` datetime(3) DEFAULT 'NULL', + `created_at` datetime(3) NOT NULL DEFAULT 'current_timestamp(3)', + `updated_at` datetime(3) DEFAULT 'NULL', + CONSTRAINT `public_api_key` UNIQUE(`public_key`,`api_version`) +); +--> statement-breakpoint +CREATE TABLE `login_elopage_buys` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `elopage_user_id` int(11) DEFAULT 'NULL', + `affiliate_program_id` int(11) DEFAULT 'NULL', + `publisher_id` int(11) DEFAULT 'NULL', + `order_id` int(11) DEFAULT 'NULL', + `product_id` int(11) DEFAULT 'NULL', + `product_price` int(11) NOT NULL, + `payer_email` varchar(255) NOT NULL, + `publisher_email` varchar(255) NOT NULL, + `payed` tinyint(4) NOT NULL, + `success_date` datetime NOT NULL, + `event` varchar(255) NOT NULL +); +--> statement-breakpoint +CREATE TABLE `migrations` ( + `version` int(11) DEFAULT 'NULL', + `fileName` varchar(256) DEFAULT 'NULL', + `date` datetime DEFAULT 'current_timestamp()' +); +--> statement-breakpoint +CREATE TABLE `openai_threads` ( + `id` varchar(128) NOT NULL, + `createdAt` timestamp DEFAULT 'current_timestamp()', + `updatedAt` timestamp DEFAULT 'current_timestamp()', + `user_id` int(10) unsigned NOT NULL +); +--> statement-breakpoint +CREATE TABLE `pending_transactions` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `state` int(10) NOT NULL, + `previous` int(10) unsigned DEFAULT 'NULL', + `type_id` int(10) DEFAULT 'NULL', + `transaction_link_id` int(10) unsigned DEFAULT 'NULL', + `amount` decimal(40,20) DEFAULT 'NULL', + `balance` decimal(40,20) DEFAULT 'NULL', + `balance_date` datetime(3) NOT NULL DEFAULT 'current_timestamp(3)', + `decay` decimal(40,20) DEFAULT 'NULL', + `decay_start` datetime(3) DEFAULT 'NULL', + `memo` varchar(512) NOT NULL, + `creation_date` datetime(3) DEFAULT 'NULL', + `user_id` int(10) unsigned NOT NULL, + `user_gradido_id` char(36) NOT NULL, + `user_name` varchar(512) DEFAULT 'NULL', + `user_community_uuid` char(36) NOT NULL, + `linked_user_id` int(10) unsigned DEFAULT 'NULL', + `linked_user_gradido_id` char(36) NOT NULL, + `linked_user_name` varchar(512) DEFAULT 'NULL', + `linked_user_community_uuid` char(36) NOT NULL, + `linked_transaction_id` int(10) DEFAULT 'NULL' +); +--> statement-breakpoint +CREATE TABLE `project_brandings` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `name` varchar(255) NOT NULL, + `alias` varchar(32) NOT NULL, + `description` text DEFAULT 'NULL', + `space_id` int(10) unsigned DEFAULT 'NULL', + `space_url` varchar(255) DEFAULT 'NULL', + `new_user_to_space` tinyint(1) NOT NULL DEFAULT 0, + `logo_url` varchar(255) DEFAULT 'NULL' +); +--> statement-breakpoint +CREATE TABLE `transactions` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `previous` int(10) unsigned DEFAULT 'NULL', + `type_id` int(10) DEFAULT 'NULL', + `transaction_link_id` int(10) unsigned DEFAULT 'NULL', + `amount` decimal(40,20) DEFAULT 'NULL', + `balance` decimal(40,20) DEFAULT 'NULL', + `balance_date` datetime(3) NOT NULL DEFAULT 'current_timestamp(3)', + `decay` decimal(40,20) DEFAULT 'NULL', + `decay_start` datetime(3) DEFAULT 'NULL', + `memo` varchar(512) NOT NULL, + `creation_date` datetime(3) DEFAULT 'NULL', + `user_id` int(10) unsigned NOT NULL, + `user_community_uuid` char(36) DEFAULT 'NULL', + `user_gradido_id` char(36) NOT NULL, + `user_name` varchar(512) DEFAULT 'NULL', + `linked_user_id` int(10) unsigned DEFAULT 'NULL', + `linked_user_community_uuid` char(36) DEFAULT 'NULL', + `linked_user_gradido_id` char(36) DEFAULT 'NULL', + `linked_user_name` varchar(512) DEFAULT 'NULL', + `linked_transaction_id` int(10) DEFAULT 'NULL', + CONSTRAINT `previous` UNIQUE(`previous`) +); +--> statement-breakpoint +CREATE TABLE `transaction_links` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `userId` int(10) unsigned NOT NULL, + `amount` decimal(40,20) NOT NULL, + `hold_available_amount` decimal(40,20) NOT NULL, + `memo` varchar(512) NOT NULL, + `code` varchar(24) NOT NULL, + `createdAt` datetime NOT NULL, + `deletedAt` datetime DEFAULT 'NULL', + `validUntil` datetime NOT NULL, + `redeemedAt` datetime DEFAULT 'NULL', + `redeemedBy` int(10) unsigned DEFAULT 'NULL' +); +--> statement-breakpoint +CREATE TABLE `users` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `foreign` tinyint(1) NOT NULL DEFAULT 0, + `gradido_id` char(36) NOT NULL, + `community_uuid` varchar(36) DEFAULT 'NULL', + `alias` varchar(20) DEFAULT 'NULL', + `email_id` int(10) DEFAULT 'NULL', + `first_name` varchar(255) DEFAULT 'NULL', + `last_name` varchar(255) DEFAULT 'NULL', + `gms_publish_name` int(10) unsigned NOT NULL DEFAULT 0, + `humhub_publish_name` int(10) unsigned NOT NULL DEFAULT 0, + `deleted_at` datetime(3) DEFAULT 'NULL', + `password` bigint(20) unsigned DEFAULT 0, + `password_encryption_type` int(10) NOT NULL DEFAULT 0, + `created_at` datetime(3) NOT NULL DEFAULT 'current_timestamp(3)', + `language` varchar(4) NOT NULL DEFAULT '''de''', + `referrer_id` int(10) unsigned DEFAULT 'NULL', + `contribution_link_id` int(10) unsigned DEFAULT 'NULL', + `publisher_id` int(11) DEFAULT 0, + `hideAmountGDD` tinyint(1) DEFAULT 0, + `hideAmountGDT` tinyint(1) DEFAULT 0, + `gms_allowed` tinyint(1) NOT NULL DEFAULT 1, + `location` geometry DEFAULT 'NULL', + `gms_publish_location` int(10) unsigned NOT NULL DEFAULT 2, + `gms_registered` tinyint(1) NOT NULL DEFAULT 0, + `gms_registered_at` datetime(3) DEFAULT 'NULL', + `humhub_allowed` tinyint(1) NOT NULL DEFAULT 0, + CONSTRAINT `uuid_key` UNIQUE(`gradido_id`,`community_uuid`), + CONSTRAINT `alias_key` UNIQUE(`alias`,`community_uuid`), + CONSTRAINT `email_id` UNIQUE(`email_id`) +); +--> statement-breakpoint +CREATE TABLE `user_contacts` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `type` varchar(100) NOT NULL, + `user_id` int(10) unsigned NOT NULL, + `email` varchar(255) NOT NULL, + `email_verification_code` bigint(20) unsigned DEFAULT 'NULL', + `email_opt_in_type_id` int(11) DEFAULT 'NULL', + `email_resend_count` int(11) DEFAULT 0, + `email_checked` tinyint(4) NOT NULL DEFAULT 0, + `gms_publish_email` tinyint(1) NOT NULL DEFAULT 0, + `country_code` varchar(255) DEFAULT 'NULL', + `phone` varchar(255) DEFAULT 'NULL', + `gms_publish_phone` int(10) unsigned NOT NULL DEFAULT 0, + `created_at` datetime(3) NOT NULL DEFAULT 'current_timestamp(3)', + `updated_at` datetime(3) DEFAULT 'NULL', + `deleted_at` datetime(3) DEFAULT 'NULL', + CONSTRAINT `email` UNIQUE(`email`), + CONSTRAINT `email_verification_code` UNIQUE(`email_verification_code`) +); +--> statement-breakpoint +CREATE TABLE `user_roles` ( + `id` int(10) unsigned AUTO_INCREMENT NOT NULL, + `user_id` int(10) unsigned NOT NULL, + `role` varchar(40) NOT NULL, + `created_at` datetime(3) NOT NULL DEFAULT 'current_timestamp(3)', + `updated_at` datetime(3) DEFAULT 'NULL' +); +--> statement-breakpoint +CREATE INDEX `idx_public_key` ON `community_handshake_states` (`public_key`);--> statement-breakpoint +CREATE INDEX `user_id` ON `contributions` (`user_id`);--> statement-breakpoint +CREATE INDEX `created_at` ON `contributions` (`created_at`);--> statement-breakpoint +CREATE INDEX `deleted_at` ON `contributions` (`deleted_at`);--> statement-breakpoint +CREATE INDEX `contribution_id` ON `contribution_messages` (`contribution_id`);--> statement-breakpoint +CREATE INDEX `user_id` ON `transactions` (`user_id`);--> statement-breakpoint +CREATE INDEX `user_id` ON `user_roles` (`user_id`); +*/ \ No newline at end of file diff --git a/database/drizzle/meta/0000_snapshot.json b/database/drizzle/meta/0000_snapshot.json new file mode 100644 index 000000000..955a78aea --- /dev/null +++ b/database/drizzle/meta/0000_snapshot.json @@ -0,0 +1,2075 @@ +{ + "id": "00000000-0000-0000-0000-000000000000", + "prevId": "", + "version": "5", + "dialect": "mysql", + "tables": { + "communities": { + "name": "communities", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "foreign": { + "default": 1, + "autoincrement": false, + "name": "foreign", + "type": "tinyint(4)", + "primaryKey": false, + "notNull": true + }, + "url": { + "autoincrement": false, + "name": "url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "public_key": { + "autoincrement": false, + "name": "public_key", + "type": "binary(32)", + "primaryKey": false, + "notNull": true + }, + "private_key": { + "default": "'NULL'", + "autoincrement": false, + "name": "private_key", + "type": "binary(64)", + "primaryKey": false, + "notNull": false + }, + "community_uuid": { + "default": "'NULL'", + "autoincrement": false, + "name": "community_uuid", + "type": "char(36)", + "primaryKey": false, + "notNull": false + }, + "authenticated_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "authenticated_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + }, + "name": { + "default": "'NULL'", + "autoincrement": false, + "name": "name", + "type": "varchar(40)", + "primaryKey": false, + "notNull": false + }, + "description": { + "default": "'NULL'", + "autoincrement": false, + "name": "description", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "gms_api_key": { + "default": "'NULL'", + "autoincrement": false, + "name": "gms_api_key", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false + }, + "public_jwt_key": { + "default": "'NULL'", + "autoincrement": false, + "name": "public_jwt_key", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false + }, + "private_jwt_key": { + "default": "'NULL'", + "autoincrement": false, + "name": "private_jwt_key", + "type": "varchar(2048)", + "primaryKey": false, + "notNull": false + }, + "location": { + "default": "'NULL'", + "autoincrement": false, + "name": "location", + "type": "geometry", + "primaryKey": false, + "notNull": false + }, + "hiero_topic_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "hiero_topic_id", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false + }, + "creation_date": { + "default": "'NULL'", + "autoincrement": false, + "name": "creation_date", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "default": "'current_timestamp(3)'", + "autoincrement": false, + "name": "created_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "updated_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + } + }, + "compositePrimaryKeys": {}, + "indexes": {}, + "foreignKeys": {}, + "uniqueConstraints": { + "url_key": { + "name": "url_key", + "columns": [ + "url" + ] + }, + "uuid_key": { + "name": "uuid_key", + "columns": [ + "community_uuid" + ] + } + }, + "checkConstraint": {} + }, + "community_handshake_states": { + "name": "community_handshake_states", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "handshake_id": { + "autoincrement": false, + "name": "handshake_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "one_time_code": { + "default": "'NULL'", + "autoincrement": false, + "name": "one_time_code", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "public_key": { + "autoincrement": false, + "name": "public_key", + "type": "binary(32)", + "primaryKey": false, + "notNull": true + }, + "api_version": { + "autoincrement": false, + "name": "api_version", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "status": { + "default": "'''OPEN_CONNECTION'''", + "autoincrement": false, + "name": "status", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "last_error": { + "default": "'NULL'", + "autoincrement": false, + "name": "last_error", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "default": "'current_timestamp(3)'", + "autoincrement": false, + "name": "created_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "default": "'current_timestamp(3)'", + "autoincrement": false, + "name": "updated_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": true + } + }, + "compositePrimaryKeys": {}, + "indexes": { + "idx_public_key": { + "name": "idx_public_key", + "columns": [ + "public_key" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "contributions": { + "name": "contributions", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "user_id", + "type": "int(10)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": false + }, + "resubmission_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "resubmission_at", + "type": "datetime", + "primaryKey": false, + "notNull": false + }, + "contribution_date": { + "default": "'NULL'", + "autoincrement": false, + "name": "contribution_date", + "type": "datetime", + "primaryKey": false, + "notNull": false + }, + "memo": { + "autoincrement": false, + "name": "memo", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "amount": { + "autoincrement": false, + "name": "amount", + "type": "decimal(40,20)", + "primaryKey": false, + "notNull": true + }, + "moderator_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "moderator_id", + "type": "int(10)", + "primaryKey": false, + "notNull": false + }, + "contribution_link_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "contribution_link_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "confirmed_by": { + "default": "'NULL'", + "autoincrement": false, + "name": "confirmed_by", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "confirmed_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "confirmed_at", + "type": "datetime", + "primaryKey": false, + "notNull": false + }, + "denied_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "denied_at", + "type": "datetime", + "primaryKey": false, + "notNull": false + }, + "denied_by": { + "default": "'NULL'", + "autoincrement": false, + "name": "denied_by", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "contribution_type": { + "default": "'''ADMIN'''", + "autoincrement": false, + "name": "contribution_type", + "type": "varchar(12)", + "primaryKey": false, + "notNull": true + }, + "contribution_status": { + "default": "'''PENDING'''", + "autoincrement": false, + "name": "contribution_status", + "type": "varchar(12)", + "primaryKey": false, + "notNull": true + }, + "deleted_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "deleted_at", + "type": "datetime", + "primaryKey": false, + "notNull": false + }, + "transaction_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "transaction_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "updated_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "updated_at", + "type": "datetime", + "primaryKey": false, + "notNull": false + }, + "updated_by": { + "default": "'NULL'", + "autoincrement": false, + "name": "updated_by", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "deleted_by": { + "default": "'NULL'", + "autoincrement": false, + "name": "deleted_by", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + } + }, + "compositePrimaryKeys": {}, + "indexes": { + "user_id": { + "name": "user_id", + "columns": [ + "user_id" + ], + "isUnique": false + }, + "created_at": { + "name": "created_at", + "columns": [ + "created_at" + ], + "isUnique": false + }, + "deleted_at": { + "name": "deleted_at", + "columns": [ + "deleted_at" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "contribution_links": { + "name": "contribution_links", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "name": { + "autoincrement": false, + "name": "name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "memo": { + "autoincrement": false, + "name": "memo", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "valid_from": { + "autoincrement": false, + "name": "valid_from", + "type": "datetime", + "primaryKey": false, + "notNull": true + }, + "valid_to": { + "default": "'NULL'", + "autoincrement": false, + "name": "valid_to", + "type": "datetime", + "primaryKey": false, + "notNull": false + }, + "amount": { + "autoincrement": false, + "name": "amount", + "type": "bigint(20)", + "primaryKey": false, + "notNull": true + }, + "cycle": { + "default": "'''ONCE'''", + "autoincrement": false, + "name": "cycle", + "type": "varchar(12)", + "primaryKey": false, + "notNull": true + }, + "max_per_cycle": { + "default": 1, + "autoincrement": false, + "name": "max_per_cycle", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "max_amount_per_month": { + "default": "'NULL'", + "autoincrement": false, + "name": "max_amount_per_month", + "type": "bigint(20)", + "primaryKey": false, + "notNull": false + }, + "total_max_count_of_contribution": { + "default": "'NULL'", + "autoincrement": false, + "name": "total_max_count_of_contribution", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "max_account_balance": { + "default": "'NULL'", + "autoincrement": false, + "name": "max_account_balance", + "type": "bigint(20)", + "primaryKey": false, + "notNull": false + }, + "min_gap_hours": { + "default": "'NULL'", + "autoincrement": false, + "name": "min_gap_hours", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "default": "'current_timestamp()'", + "autoincrement": false, + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": true + }, + "deleted_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "deleted_at", + "type": "datetime", + "primaryKey": false, + "notNull": false + }, + "code": { + "autoincrement": false, + "name": "code", + "type": "varchar(24)", + "primaryKey": false, + "notNull": true + }, + "link_enabled": { + "default": 1, + "autoincrement": false, + "name": "link_enabled", + "type": "tinyint(4)", + "primaryKey": false, + "notNull": true + } + }, + "compositePrimaryKeys": {}, + "indexes": {}, + "foreignKeys": {}, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "contribution_messages": { + "name": "contribution_messages", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "contribution_id": { + "autoincrement": false, + "name": "contribution_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "autoincrement": false, + "name": "user_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "message": { + "autoincrement": false, + "name": "message", + "type": "varchar(2000)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "default": "'current_timestamp()'", + "autoincrement": false, + "name": "created_at", + "type": "datetime", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "updated_at", + "type": "datetime", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "deleted_at", + "type": "datetime", + "primaryKey": false, + "notNull": false + }, + "deleted_by": { + "default": "'NULL'", + "autoincrement": false, + "name": "deleted_by", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "type": { + "default": "'''DIALOG'''", + "autoincrement": false, + "name": "type", + "type": "varchar(12)", + "primaryKey": false, + "notNull": true + }, + "is_moderator": { + "default": 0, + "autoincrement": false, + "name": "is_moderator", + "type": "tinyint(1)", + "primaryKey": false, + "notNull": true + } + }, + "compositePrimaryKeys": {}, + "indexes": { + "contribution_id": { + "name": "contribution_id", + "columns": [ + "contribution_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "dlt_transactions": { + "name": "dlt_transactions", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "transaction_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "transaction_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "user_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "transaction_link_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "transaction_link_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "type_id": { + "autoincrement": false, + "name": "type_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "message_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "message_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false + }, + "verified": { + "default": 0, + "autoincrement": false, + "name": "verified", + "type": "tinyint(4)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "default": "'current_timestamp(3)'", + "autoincrement": false, + "name": "created_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": true + }, + "verified_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "verified_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + }, + "error": { + "default": "'NULL'", + "autoincrement": false, + "name": "error", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "compositePrimaryKeys": {}, + "indexes": {}, + "foreignKeys": {}, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "events": { + "name": "events", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "type": { + "autoincrement": false, + "name": "type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "default": "'current_timestamp(3)'", + "autoincrement": false, + "name": "created_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": true + }, + "affected_user_id": { + "autoincrement": false, + "name": "affected_user_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "acting_user_id": { + "autoincrement": false, + "name": "acting_user_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "involved_user_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "involved_user_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "involved_transaction_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "involved_transaction_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "involved_contribution_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "involved_contribution_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "involved_contribution_message_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "involved_contribution_message_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "involved_transaction_link_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "involved_transaction_link_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "involved_contribution_link_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "involved_contribution_link_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "amount": { + "default": "'NULL'", + "autoincrement": false, + "name": "amount", + "type": "bigint(20)", + "primaryKey": false, + "notNull": false + } + }, + "compositePrimaryKeys": {}, + "indexes": {}, + "foreignKeys": {}, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "federated_communities": { + "name": "federated_communities", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "foreign": { + "default": 1, + "autoincrement": false, + "name": "foreign", + "type": "tinyint(4)", + "primaryKey": false, + "notNull": true + }, + "public_key": { + "autoincrement": false, + "name": "public_key", + "type": "binary(32)", + "primaryKey": false, + "notNull": true + }, + "api_version": { + "autoincrement": false, + "name": "api_version", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true + }, + "end_point": { + "autoincrement": false, + "name": "end_point", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "last_announced_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "last_announced_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + }, + "verified_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "verified_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + }, + "last_error_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "last_error_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "default": "'current_timestamp(3)'", + "autoincrement": false, + "name": "created_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "updated_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + } + }, + "compositePrimaryKeys": {}, + "indexes": {}, + "foreignKeys": {}, + "uniqueConstraints": { + "public_api_key": { + "name": "public_api_key", + "columns": [ + "public_key", + "api_version" + ] + } + }, + "checkConstraint": {} + }, + "login_elopage_buys": { + "name": "login_elopage_buys", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "elopage_user_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "elopage_user_id", + "type": "int(11)", + "primaryKey": false, + "notNull": false + }, + "affiliate_program_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "affiliate_program_id", + "type": "int(11)", + "primaryKey": false, + "notNull": false + }, + "publisher_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "publisher_id", + "type": "int(11)", + "primaryKey": false, + "notNull": false + }, + "order_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "order_id", + "type": "int(11)", + "primaryKey": false, + "notNull": false + }, + "product_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "product_id", + "type": "int(11)", + "primaryKey": false, + "notNull": false + }, + "product_price": { + "autoincrement": false, + "name": "product_price", + "type": "int(11)", + "primaryKey": false, + "notNull": true + }, + "payer_email": { + "autoincrement": false, + "name": "payer_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "publisher_email": { + "autoincrement": false, + "name": "publisher_email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "payed": { + "autoincrement": false, + "name": "payed", + "type": "tinyint(4)", + "primaryKey": false, + "notNull": true + }, + "success_date": { + "autoincrement": false, + "name": "success_date", + "type": "datetime", + "primaryKey": false, + "notNull": true + }, + "event": { + "autoincrement": false, + "name": "event", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + } + }, + "compositePrimaryKeys": {}, + "indexes": {}, + "foreignKeys": {}, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "migrations": { + "name": "migrations", + "columns": { + "version": { + "default": "'NULL'", + "autoincrement": false, + "name": "version", + "type": "int(11)", + "primaryKey": false, + "notNull": false + }, + "fileName": { + "default": "'NULL'", + "autoincrement": false, + "name": "fileName", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "date": { + "default": "'current_timestamp()'", + "autoincrement": false, + "name": "date", + "type": "datetime", + "primaryKey": false, + "notNull": false + } + }, + "compositePrimaryKeys": {}, + "indexes": {}, + "foreignKeys": {}, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "openai_threads": { + "name": "openai_threads", + "columns": { + "id": { + "autoincrement": false, + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true + }, + "createdAt": { + "default": "'current_timestamp()'", + "autoincrement": false, + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "updatedAt": { + "default": "'current_timestamp()'", + "autoincrement": false, + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "autoincrement": false, + "name": "user_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + } + }, + "compositePrimaryKeys": {}, + "indexes": {}, + "foreignKeys": {}, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "pending_transactions": { + "name": "pending_transactions", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "state": { + "autoincrement": false, + "name": "state", + "type": "int(10)", + "primaryKey": false, + "notNull": true + }, + "previous": { + "default": "'NULL'", + "autoincrement": false, + "name": "previous", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "type_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "type_id", + "type": "int(10)", + "primaryKey": false, + "notNull": false + }, + "transaction_link_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "transaction_link_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "amount": { + "default": "'NULL'", + "autoincrement": false, + "name": "amount", + "type": "decimal(40,20)", + "primaryKey": false, + "notNull": false + }, + "balance": { + "default": "'NULL'", + "autoincrement": false, + "name": "balance", + "type": "decimal(40,20)", + "primaryKey": false, + "notNull": false + }, + "balance_date": { + "default": "'current_timestamp(3)'", + "autoincrement": false, + "name": "balance_date", + "type": "datetime(3)", + "primaryKey": false, + "notNull": true + }, + "decay": { + "default": "'NULL'", + "autoincrement": false, + "name": "decay", + "type": "decimal(40,20)", + "primaryKey": false, + "notNull": false + }, + "decay_start": { + "default": "'NULL'", + "autoincrement": false, + "name": "decay_start", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + }, + "memo": { + "autoincrement": false, + "name": "memo", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "creation_date": { + "default": "'NULL'", + "autoincrement": false, + "name": "creation_date", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "autoincrement": false, + "name": "user_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "user_gradido_id": { + "autoincrement": false, + "name": "user_gradido_id", + "type": "char(36)", + "primaryKey": false, + "notNull": true + }, + "user_name": { + "default": "'NULL'", + "autoincrement": false, + "name": "user_name", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false + }, + "user_community_uuid": { + "autoincrement": false, + "name": "user_community_uuid", + "type": "char(36)", + "primaryKey": false, + "notNull": true + }, + "linked_user_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "linked_user_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "linked_user_gradido_id": { + "autoincrement": false, + "name": "linked_user_gradido_id", + "type": "char(36)", + "primaryKey": false, + "notNull": true + }, + "linked_user_name": { + "default": "'NULL'", + "autoincrement": false, + "name": "linked_user_name", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false + }, + "linked_user_community_uuid": { + "autoincrement": false, + "name": "linked_user_community_uuid", + "type": "char(36)", + "primaryKey": false, + "notNull": true + }, + "linked_transaction_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "linked_transaction_id", + "type": "int(10)", + "primaryKey": false, + "notNull": false + } + }, + "compositePrimaryKeys": {}, + "indexes": {}, + "foreignKeys": {}, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "project_brandings": { + "name": "project_brandings", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "name": { + "autoincrement": false, + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "alias": { + "autoincrement": false, + "name": "alias", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true + }, + "description": { + "default": "'NULL'", + "autoincrement": false, + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "space_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "space_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "space_url": { + "default": "'NULL'", + "autoincrement": false, + "name": "space_url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "new_user_to_space": { + "default": 0, + "autoincrement": false, + "name": "new_user_to_space", + "type": "tinyint(1)", + "primaryKey": false, + "notNull": true + }, + "logo_url": { + "default": "'NULL'", + "autoincrement": false, + "name": "logo_url", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "compositePrimaryKeys": {}, + "indexes": {}, + "foreignKeys": {}, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "transactions": { + "name": "transactions", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "previous": { + "default": "'NULL'", + "autoincrement": false, + "name": "previous", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "type_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "type_id", + "type": "int(10)", + "primaryKey": false, + "notNull": false + }, + "transaction_link_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "transaction_link_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "amount": { + "default": "'NULL'", + "autoincrement": false, + "name": "amount", + "type": "decimal(40,20)", + "primaryKey": false, + "notNull": false + }, + "balance": { + "default": "'NULL'", + "autoincrement": false, + "name": "balance", + "type": "decimal(40,20)", + "primaryKey": false, + "notNull": false + }, + "balance_date": { + "default": "'current_timestamp(3)'", + "autoincrement": false, + "name": "balance_date", + "type": "datetime(3)", + "primaryKey": false, + "notNull": true + }, + "decay": { + "default": "'NULL'", + "autoincrement": false, + "name": "decay", + "type": "decimal(40,20)", + "primaryKey": false, + "notNull": false + }, + "decay_start": { + "default": "'NULL'", + "autoincrement": false, + "name": "decay_start", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + }, + "memo": { + "autoincrement": false, + "name": "memo", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "creation_date": { + "default": "'NULL'", + "autoincrement": false, + "name": "creation_date", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "autoincrement": false, + "name": "user_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "user_community_uuid": { + "default": "'NULL'", + "autoincrement": false, + "name": "user_community_uuid", + "type": "char(36)", + "primaryKey": false, + "notNull": false + }, + "user_gradido_id": { + "autoincrement": false, + "name": "user_gradido_id", + "type": "char(36)", + "primaryKey": false, + "notNull": true + }, + "user_name": { + "default": "'NULL'", + "autoincrement": false, + "name": "user_name", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false + }, + "linked_user_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "linked_user_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "linked_user_community_uuid": { + "default": "'NULL'", + "autoincrement": false, + "name": "linked_user_community_uuid", + "type": "char(36)", + "primaryKey": false, + "notNull": false + }, + "linked_user_gradido_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "linked_user_gradido_id", + "type": "char(36)", + "primaryKey": false, + "notNull": false + }, + "linked_user_name": { + "default": "'NULL'", + "autoincrement": false, + "name": "linked_user_name", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false + }, + "linked_transaction_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "linked_transaction_id", + "type": "int(10)", + "primaryKey": false, + "notNull": false + } + }, + "compositePrimaryKeys": {}, + "indexes": { + "user_id": { + "name": "user_id", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "uniqueConstraints": { + "previous": { + "name": "previous", + "columns": [ + "previous" + ] + } + }, + "checkConstraint": {} + }, + "transaction_links": { + "name": "transaction_links", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "userId": { + "autoincrement": false, + "name": "userId", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "amount": { + "autoincrement": false, + "name": "amount", + "type": "decimal(40,20)", + "primaryKey": false, + "notNull": true + }, + "hold_available_amount": { + "autoincrement": false, + "name": "hold_available_amount", + "type": "decimal(40,20)", + "primaryKey": false, + "notNull": true + }, + "memo": { + "autoincrement": false, + "name": "memo", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true + }, + "code": { + "autoincrement": false, + "name": "code", + "type": "varchar(24)", + "primaryKey": false, + "notNull": true + }, + "createdAt": { + "autoincrement": false, + "name": "createdAt", + "type": "datetime", + "primaryKey": false, + "notNull": true + }, + "deletedAt": { + "default": "'NULL'", + "autoincrement": false, + "name": "deletedAt", + "type": "datetime", + "primaryKey": false, + "notNull": false + }, + "validUntil": { + "autoincrement": false, + "name": "validUntil", + "type": "datetime", + "primaryKey": false, + "notNull": true + }, + "redeemedAt": { + "default": "'NULL'", + "autoincrement": false, + "name": "redeemedAt", + "type": "datetime", + "primaryKey": false, + "notNull": false + }, + "redeemedBy": { + "default": "'NULL'", + "autoincrement": false, + "name": "redeemedBy", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + } + }, + "compositePrimaryKeys": {}, + "indexes": {}, + "foreignKeys": {}, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "users": { + "name": "users", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "foreign": { + "default": 0, + "autoincrement": false, + "name": "foreign", + "type": "tinyint(1)", + "primaryKey": false, + "notNull": true + }, + "gradido_id": { + "autoincrement": false, + "name": "gradido_id", + "type": "char(36)", + "primaryKey": false, + "notNull": true + }, + "community_uuid": { + "default": "'NULL'", + "autoincrement": false, + "name": "community_uuid", + "type": "varchar(36)", + "primaryKey": false, + "notNull": false + }, + "alias": { + "default": "'NULL'", + "autoincrement": false, + "name": "alias", + "type": "varchar(20)", + "primaryKey": false, + "notNull": false + }, + "email_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "email_id", + "type": "int(10)", + "primaryKey": false, + "notNull": false + }, + "first_name": { + "default": "'NULL'", + "autoincrement": false, + "name": "first_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "last_name": { + "default": "'NULL'", + "autoincrement": false, + "name": "last_name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "gms_publish_name": { + "default": 0, + "autoincrement": false, + "name": "gms_publish_name", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "humhub_publish_name": { + "default": 0, + "autoincrement": false, + "name": "humhub_publish_name", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "deleted_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "deleted_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + }, + "password": { + "default": 0, + "autoincrement": false, + "name": "password", + "type": "bigint(20) unsigned", + "primaryKey": false, + "notNull": false + }, + "password_encryption_type": { + "default": 0, + "autoincrement": false, + "name": "password_encryption_type", + "type": "int(10)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "default": "'current_timestamp(3)'", + "autoincrement": false, + "name": "created_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": true + }, + "language": { + "default": "'''de'''", + "autoincrement": false, + "name": "language", + "type": "varchar(4)", + "primaryKey": false, + "notNull": true + }, + "referrer_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "referrer_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "contribution_link_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "contribution_link_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": false + }, + "publisher_id": { + "default": 0, + "autoincrement": false, + "name": "publisher_id", + "type": "int(11)", + "primaryKey": false, + "notNull": false + }, + "hideAmountGDD": { + "default": 0, + "autoincrement": false, + "name": "hideAmountGDD", + "type": "tinyint(1)", + "primaryKey": false, + "notNull": false + }, + "hideAmountGDT": { + "default": 0, + "autoincrement": false, + "name": "hideAmountGDT", + "type": "tinyint(1)", + "primaryKey": false, + "notNull": false + }, + "gms_allowed": { + "default": 1, + "autoincrement": false, + "name": "gms_allowed", + "type": "tinyint(1)", + "primaryKey": false, + "notNull": true + }, + "location": { + "default": "'NULL'", + "autoincrement": false, + "name": "location", + "type": "geometry", + "primaryKey": false, + "notNull": false + }, + "gms_publish_location": { + "default": 2, + "autoincrement": false, + "name": "gms_publish_location", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "gms_registered": { + "default": 0, + "autoincrement": false, + "name": "gms_registered", + "type": "tinyint(1)", + "primaryKey": false, + "notNull": true + }, + "gms_registered_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "gms_registered_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + }, + "humhub_allowed": { + "default": 0, + "autoincrement": false, + "name": "humhub_allowed", + "type": "tinyint(1)", + "primaryKey": false, + "notNull": true + } + }, + "compositePrimaryKeys": {}, + "indexes": {}, + "foreignKeys": {}, + "uniqueConstraints": { + "uuid_key": { + "name": "uuid_key", + "columns": [ + "gradido_id", + "community_uuid" + ] + }, + "alias_key": { + "name": "alias_key", + "columns": [ + "alias", + "community_uuid" + ] + }, + "email_id": { + "name": "email_id", + "columns": [ + "email_id" + ] + } + }, + "checkConstraint": {} + }, + "user_contacts": { + "name": "user_contacts", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "type": { + "autoincrement": false, + "name": "type", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "autoincrement": false, + "name": "user_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "email": { + "autoincrement": false, + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "email_verification_code": { + "default": "'NULL'", + "autoincrement": false, + "name": "email_verification_code", + "type": "bigint(20) unsigned", + "primaryKey": false, + "notNull": false + }, + "email_opt_in_type_id": { + "default": "'NULL'", + "autoincrement": false, + "name": "email_opt_in_type_id", + "type": "int(11)", + "primaryKey": false, + "notNull": false + }, + "email_resend_count": { + "default": 0, + "autoincrement": false, + "name": "email_resend_count", + "type": "int(11)", + "primaryKey": false, + "notNull": false + }, + "email_checked": { + "default": 0, + "autoincrement": false, + "name": "email_checked", + "type": "tinyint(4)", + "primaryKey": false, + "notNull": true + }, + "gms_publish_email": { + "default": 0, + "autoincrement": false, + "name": "gms_publish_email", + "type": "tinyint(1)", + "primaryKey": false, + "notNull": true + }, + "country_code": { + "default": "'NULL'", + "autoincrement": false, + "name": "country_code", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "phone": { + "default": "'NULL'", + "autoincrement": false, + "name": "phone", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "gms_publish_phone": { + "default": 0, + "autoincrement": false, + "name": "gms_publish_phone", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "default": "'current_timestamp(3)'", + "autoincrement": false, + "name": "created_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "updated_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "deleted_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + } + }, + "compositePrimaryKeys": {}, + "indexes": {}, + "foreignKeys": {}, + "uniqueConstraints": { + "email": { + "name": "email", + "columns": [ + "email" + ] + }, + "email_verification_code": { + "name": "email_verification_code", + "columns": [ + "email_verification_code" + ] + } + }, + "checkConstraint": {} + }, + "user_roles": { + "name": "user_roles", + "columns": { + "id": { + "autoincrement": true, + "name": "id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "autoincrement": false, + "name": "user_id", + "type": "int(10) unsigned", + "primaryKey": false, + "notNull": true + }, + "role": { + "autoincrement": false, + "name": "role", + "type": "varchar(40)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "default": "'current_timestamp(3)'", + "autoincrement": false, + "name": "created_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "default": "'NULL'", + "autoincrement": false, + "name": "updated_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false + } + }, + "compositePrimaryKeys": {}, + "indexes": { + "user_id": { + "name": "user_id", + "columns": [ + "user_id" + ], + "isUnique": false + } + }, + "foreignKeys": {}, + "uniqueConstraints": {}, + "checkConstraint": {} + } + }, + "views": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "tables": {}, + "indexes": {} + } +} \ No newline at end of file diff --git a/database/drizzle/meta/_journal.json b/database/drizzle/meta/_journal.json new file mode 100644 index 000000000..76bad422c --- /dev/null +++ b/database/drizzle/meta/_journal.json @@ -0,0 +1,13 @@ +{ + "version": "7", + "dialect": "mysql", + "entries": [ + { + "idx": 0, + "version": "5", + "when": 1763567731001, + "tag": "0000_unusual_the_order", + "breakpoints": true + } + ] +} \ No newline at end of file diff --git a/database/drizzle/schema.ts b/database/drizzle/schema.ts new file mode 100644 index 000000000..56977a189 --- /dev/null +++ b/database/drizzle/schema.ts @@ -0,0 +1,321 @@ +import { mysqlTable, mysqlSchema, AnyMySqlColumn, unique, int, varchar, binary, char, datetime, index, text, decimal, timestamp, tinyint, bigint } from "drizzle-orm/mysql-core" +import { sql } from "drizzle-orm" + +export const communities = mysqlTable("communities", { + id: int().autoincrement().notNull(), + foreign: tinyint().default(1).notNull(), + url: varchar({ length: 255 }).notNull(), + publicKey: binary("public_key", { length: 32 }).notNull(), + privateKey: binary("private_key", { length: 64 }).default(sql`NULL`), + communityUuid: char("community_uuid", { length: 36 }).default(sql`NULL`), + authenticatedAt: datetime("authenticated_at", { mode: 'string', fsp: 3 }).default(sql`NULL`), + name: varchar({ length: 40 }).default(sql`NULL`), + description: varchar({ length: 255 }).default(sql`NULL`), + gmsApiKey: varchar("gms_api_key", { length: 512 }).default(sql`NULL`), + publicJwtKey: varchar("public_jwt_key", { length: 512 }).default(sql`NULL`), + privateJwtKey: varchar("private_jwt_key", { length: 2048 }).default(sql`NULL`), + // Warning: Can't parse geometry from database + // geometryType: geometry("location"), + hieroTopicId: varchar("hiero_topic_id", { length: 512 }).default(sql`NULL`), + creationDate: datetime("creation_date", { mode: 'string', fsp: 3 }).default(sql`NULL`), + createdAt: datetime("created_at", { mode: 'string', fsp: 3 }).default(sql`current_timestamp(3)`).notNull(), + updatedAt: datetime("updated_at", { mode: 'string', fsp: 3 }).default(sql`NULL`), +}, +(table) => [ + unique("url_key").on(table.url), + unique("uuid_key").on(table.communityUuid), +]); + +export const communityHandshakeStates = mysqlTable("community_handshake_states", { + id: int().autoincrement().notNull(), + handshakeId: int("handshake_id").notNull(), + oneTimeCode: int("one_time_code").default(sql`NULL`), + publicKey: binary("public_key", { length: 32 }).notNull(), + apiVersion: varchar("api_version", { length: 255 }).notNull(), + status: varchar({ length: 255 }).default('\'OPEN_CONNECTION\'').notNull(), + lastError: text("last_error").default(sql`NULL`), + createdAt: datetime("created_at", { mode: 'string', fsp: 3 }).default(sql`current_timestamp(3)`).notNull(), + updatedAt: datetime("updated_at", { mode: 'string', fsp: 3 }).default(sql`NULL`), +}, +(table) => [ + index("idx_public_key").on(table.publicKey), +]); + +export const contributions = mysqlTable("contributions", { + id: int().autoincrement().notNull(), + userId: int("user_id").default(sql`NULL`), + createdAt: datetime("created_at", { mode: 'string'}).default(sql`NULL`), + resubmissionAt: datetime("resubmission_at", { mode: 'string'}).default(sql`NULL`), + contributionDate: datetime("contribution_date", { mode: 'string'}).default(sql`NULL`), + memo: varchar({ length: 512 }).notNull(), + amount: decimal({ precision: 40, scale: 20 }).notNull(), + moderatorId: int("moderator_id").default(sql`NULL`), + contributionLinkId: int("contribution_link_id").default(sql`NULL`), + confirmedBy: int("confirmed_by").default(sql`NULL`), + confirmedAt: datetime("confirmed_at", { mode: 'string'}).default(sql`NULL`), + deniedAt: datetime("denied_at", { mode: 'string'}).default(sql`NULL`), + deniedBy: int("denied_by").default(sql`NULL`), + contributionType: varchar("contribution_type", { length: 12 }).default('\'ADMIN\'').notNull(), + contributionStatus: varchar("contribution_status", { length: 12 }).default('\'PENDING\'').notNull(), + deletedAt: datetime("deleted_at", { mode: 'string'}).default(sql`NULL`), + transactionId: int("transaction_id").default(sql`NULL`), + updatedAt: datetime("updated_at", { mode: 'string'}).default(sql`NULL`), + updatedBy: int("updated_by").default(sql`NULL`), + deletedBy: int("deleted_by").default(sql`NULL`), +}, +(table) => [ + index("user_id").on(table.userId), + index("created_at").on(table.createdAt), + index("deleted_at").on(table.deletedAt), +]); + +export const contributionLinks = mysqlTable("contribution_links", { + id: int().autoincrement().notNull(), + name: varchar({ length: 100 }).notNull(), + memo: varchar({ length: 512 }).notNull(), + validFrom: datetime("valid_from", { mode: 'string'}).notNull(), + validTo: datetime("valid_to", { mode: 'string'}).default(sql`NULL`), + amount: bigint({ mode: "number" }).notNull(), + cycle: varchar({ length: 12 }).default('\'ONCE\'').notNull(), + maxPerCycle: int("max_per_cycle").default(1).notNull(), + maxAmountPerMonth: bigint("max_amount_per_month", { mode: "number" }).default(sql`NULL`), + totalMaxCountOfContribution: int("total_max_count_of_contribution").default(sql`NULL`), + maxAccountBalance: bigint("max_account_balance", { mode: "number" }).default(sql`NULL`), + minGapHours: int("min_gap_hours").default(sql`NULL`), + createdAt: datetime("created_at", { mode: 'string'}).default(sql`current_timestamp()`).notNull(), + deletedAt: datetime("deleted_at", { mode: 'string'}).default(sql`NULL`), + code: varchar({ length: 24 }).notNull(), + linkEnabled: tinyint("link_enabled").default(1).notNull(), +}); + +export const contributionMessages = mysqlTable("contribution_messages", { + id: int().autoincrement().notNull(), + contributionId: int("contribution_id").notNull(), + userId: int("user_id").notNull(), + message: varchar({ length: 2000 }).notNull(), + createdAt: datetime("created_at", { mode: 'string'}).default(sql`current_timestamp()`).notNull(), + updatedAt: datetime("updated_at", { mode: 'string'}).default(sql`NULL`), + deletedAt: datetime("deleted_at", { mode: 'string'}).default(sql`NULL`), + deletedBy: int("deleted_by").default(sql`NULL`), + type: varchar({ length: 12 }).default('\'DIALOG\'').notNull(), + isModerator: tinyint("is_moderator").default(0).notNull(), +}, +(table) => [ + index("contribution_id").on(table.contributionId), +]); + +export const dltTransactions = mysqlTable("dlt_transactions", { + id: int().autoincrement().notNull(), + transactionId: int("transaction_id").default(sql`NULL`), + userId: int("user_id").default(sql`NULL`), + transactionLinkId: int("transaction_link_id").default(sql`NULL`), + typeId: int("type_id").notNull(), + messageId: varchar("message_id", { length: 64 }).default(sql`NULL`), + verified: tinyint().default(0).notNull(), + createdAt: datetime("created_at", { mode: 'string', fsp: 3 }).default(sql`current_timestamp(3)`).notNull(), + verifiedAt: datetime("verified_at", { mode: 'string', fsp: 3 }).default(sql`NULL`), + error: text().default(sql`NULL`), +}); + +export const events = mysqlTable("events", { + id: int().autoincrement().notNull(), + type: varchar({ length: 100 }).notNull(), + createdAt: datetime("created_at", { mode: 'string', fsp: 3 }).default(sql`current_timestamp(3)`).notNull(), + affectedUserId: int("affected_user_id").notNull(), + actingUserId: int("acting_user_id").notNull(), + involvedUserId: int("involved_user_id").default(sql`NULL`), + involvedTransactionId: int("involved_transaction_id").default(sql`NULL`), + involvedContributionId: int("involved_contribution_id").default(sql`NULL`), + involvedContributionMessageId: int("involved_contribution_message_id").default(sql`NULL`), + involvedTransactionLinkId: int("involved_transaction_link_id").default(sql`NULL`), + involvedContributionLinkId: int("involved_contribution_link_id").default(sql`NULL`), + amount: bigint({ mode: "number" }).default(sql`NULL`), +}); + +export const federatedCommunities = mysqlTable("federated_communities", { + id: int().autoincrement().notNull(), + foreign: tinyint().default(1).notNull(), + publicKey: binary("public_key", { length: 32 }).notNull(), + apiVersion: varchar("api_version", { length: 10 }).notNull(), + endPoint: varchar("end_point", { length: 255 }).notNull(), + lastAnnouncedAt: datetime("last_announced_at", { mode: 'string', fsp: 3 }).default('NULL'), + verifiedAt: datetime("verified_at", { mode: 'string', fsp: 3 }).default('NULL'), + lastErrorAt: datetime("last_error_at", { mode: 'string', fsp: 3 }).default('NULL'), + createdAt: datetime("created_at", { mode: 'string', fsp: 3 }).default('current_timestamp(3)').notNull(), + updatedAt: datetime("updated_at", { mode: 'string', fsp: 3 }).default('NULL'), +}, +(table) => [ + unique("public_api_key").on(table.publicKey, table.apiVersion), +]); + +export const loginElopageBuys = mysqlTable("login_elopage_buys", { + id: int().autoincrement().notNull(), + elopageUserId: int("elopage_user_id").default(sql`NULL`), + affiliateProgramId: int("affiliate_program_id").default(sql`NULL`), + publisherId: int("publisher_id").default(sql`NULL`), + orderId: int("order_id").default(sql`NULL`), + productId: int("product_id").default(sql`NULL`), + productPrice: int("product_price").notNull(), + payerEmail: varchar("payer_email", { length: 255 }).notNull(), + publisherEmail: varchar("publisher_email", { length: 255 }).notNull(), + payed: tinyint().notNull(), + successDate: datetime("success_date", { mode: 'string'}).notNull(), + event: varchar({ length: 255 }).notNull(), +}); + +export const migrations = mysqlTable("migrations", { + version: int().default(sql`NULL`), + fileName: varchar({ length: 256 }).default(sql`NULL`), + date: datetime({ mode: 'string'}).default(sql`current_timestamp()`), +}); + +export const openaiThreads = mysqlTable("openai_threads", { + id: varchar({ length: 128 }).notNull(), + createdAt: timestamp({ mode: 'string' }).default(sql`current_timestamp()`), + updatedAt: timestamp({ mode: 'string' }).default(sql`current_timestamp()`), + userId: int("user_id").notNull(), +}); + +export const pendingTransactions = mysqlTable("pending_transactions", { + id: int().autoincrement().notNull(), + state: int().notNull(), + previous: int().default(sql`NULL`), + typeId: int("type_id").default(sql`NULL`), + transactionLinkId: int("transaction_link_id").default(sql`NULL`), + amount: decimal({ precision: 40, scale: 20 }).default(sql`NULL`), + balance: decimal({ precision: 40, scale: 20 }).default(sql`NULL`), + balanceDate: datetime("balance_date", { mode: 'string', fsp: 3 }).default(sql`current_timestamp(3)`).notNull(), + decay: decimal({ precision: 40, scale: 20 }).default(sql`NULL`), + decayStart: datetime("decay_start", { mode: 'string', fsp: 3 }).default(sql`NULL`), + memo: varchar({ length: 512 }).notNull(), + creationDate: datetime("creation_date", { mode: 'string', fsp: 3 }).default(sql`NULL`), + userId: int("user_id").notNull(), + userGradidoId: char("user_gradido_id", { length: 36 }).notNull(), + userName: varchar("user_name", { length: 512 }).default(sql`NULL`), + userCommunityUuid: char("user_community_uuid", { length: 36 }).notNull(), + linkedUserId: int("linked_user_id").default(sql`NULL`), + linkedUserGradidoId: char("linked_user_gradido_id", { length: 36 }).notNull(), + linkedUserName: varchar("linked_user_name", { length: 512 }).default(sql`NULL`), + linkedUserCommunityUuid: char("linked_user_community_uuid", { length: 36 }).notNull(), + linkedTransactionId: int("linked_transaction_id").default(sql`NULL`), +}); + +export const projectBrandings = mysqlTable("project_brandings", { + id: int().autoincrement().notNull(), + name: varchar({ length: 255 }).notNull(), + alias: varchar({ length: 32 }).notNull(), + description: text().default(sql`NULL`), + spaceId: int("space_id").default(sql`NULL`), + spaceUrl: varchar("space_url", { length: 255 }).default(sql`NULL`), + newUserToSpace: tinyint("new_user_to_space").default(0).notNull(), + logoUrl: varchar("logo_url", { length: 255 }).default(sql`NULL`), +}); + +export const transactions = mysqlTable("transactions", { + id: int().autoincrement().notNull(), + previous: int().default(sql`NULL`), + typeId: int("type_id").default(sql`NULL`), + transactionLinkId: int("transaction_link_id").default(sql`NULL`), + amount: decimal({ precision: 40, scale: 20 }).default(sql`NULL`), + balance: decimal({ precision: 40, scale: 20 }).default(sql`NULL`), + balanceDate: datetime("balance_date", { mode: 'string', fsp: 3 }).default(sql`current_timestamp(3)`).notNull(), + decay: decimal({ precision: 40, scale: 20 }).default(sql`NULL`), + decayStart: datetime("decay_start", { mode: 'string', fsp: 3 }).default(sql`NULL`), + memo: varchar({ length: 512 }).notNull(), + creationDate: datetime("creation_date", { mode: 'string', fsp: 3 }).default(sql`NULL`), + userId: int("user_id").notNull(), + userCommunityUuid: char("user_community_uuid", { length: 36 }).default(sql`NULL`), + userGradidoId: char("user_gradido_id", { length: 36 }).notNull(), + userName: varchar("user_name", { length: 512 }).default(sql`NULL`), + linkedUserId: int("linked_user_id").default(sql`NULL`), + linkedUserCommunityUuid: char("linked_user_community_uuid", { length: 36 }).default(sql`NULL`), + linkedUserGradidoId: char("linked_user_gradido_id", { length: 36 }).default(sql`NULL`), + linkedUserName: varchar("linked_user_name", { length: 512 }).default(sql`NULL`), + linkedTransactionId: int("linked_transaction_id").default(sql`NULL`), +}, +(table) => [ + index("user_id").on(table.userId), + unique("previous").on(table.previous), +]); + +export const transactionLinks = mysqlTable("transaction_links", { + id: int().autoincrement().notNull(), + userId: int().notNull(), + amount: decimal({ precision: 40, scale: 20 }).notNull(), + holdAvailableAmount: decimal("hold_available_amount", { precision: 40, scale: 20 }).notNull(), + memo: varchar({ length: 512 }).notNull(), + code: varchar({ length: 24 }).notNull(), + createdAt: datetime({ mode: 'string'}).notNull(), + deletedAt: datetime({ mode: 'string'}).default(sql`NULL`), + validUntil: datetime({ mode: 'string'}).notNull(), + redeemedAt: datetime({ mode: 'string'}).default(sql`NULL`), + redeemedBy: int().default(sql`NULL`), +}); + +export const users = mysqlTable("users", { + id: int().autoincrement().notNull(), + foreign: tinyint().default(0).notNull(), + gradidoId: char("gradido_id", { length: 36 }).notNull(), + communityUuid: varchar("community_uuid", { length: 36 }).default(sql`NULL`), + alias: varchar({ length: 20 }).default(sql`NULL`), + emailId: int("email_id").default(sql`NULL`), + firstName: varchar("first_name", { length: 255 }).default(sql`NULL`), + lastName: varchar("last_name", { length: 255 }).default(sql`NULL`), + gmsPublishName: int("gms_publish_name").default(0).notNull(), + humhubPublishName: int("humhub_publish_name").default(0).notNull(), + deletedAt: datetime("deleted_at", { mode: 'string', fsp: 3 }).default(sql`NULL`), + password: bigint({ mode: "number" }), + passwordEncryptionType: int("password_encryption_type").default(0).notNull(), + createdAt: datetime("created_at", { mode: 'string', fsp: 3 }).default(sql`current_timestamp(3)`).notNull(), + language: varchar({ length: 4 }).default(sql`'de'`).notNull(), + referrerId: int("referrer_id").default(sql`NULL`), + contributionLinkId: int("contribution_link_id").default(sql`NULL`), + publisherId: int("publisher_id").default(0), + hideAmountGdd: tinyint().default(0), + hideAmountGdt: tinyint().default(0), + gmsAllowed: tinyint("gms_allowed").default(1).notNull(), + // Warning: Can't parse geometry from database + // geometryType: geometry("location"), + gmsPublishLocation: int("gms_publish_location").default(2).notNull(), + gmsRegistered: tinyint("gms_registered").default(0).notNull(), + gmsRegisteredAt: datetime("gms_registered_at", { mode: 'string', fsp: 3 }).default(sql`NULL`), + humhubAllowed: tinyint("humhub_allowed").default(0).notNull(), +}, +(table) => [ + unique("uuid_key").on(table.gradidoId, table.communityUuid), + unique("alias_key").on(table.alias, table.communityUuid), + unique("email_id").on(table.emailId), +]); + +export const userContacts = mysqlTable("user_contacts", { + id: int().autoincrement().notNull(), + type: varchar({ length: 100 }).notNull(), + userId: int("user_id").notNull(), + email: varchar({ length: 255 }).notNull(), + emailVerificationCode: bigint("email_verification_code", { mode: "number" }).default(sql`NULL`), + emailOptInTypeId: int("email_opt_in_type_id").default(sql`NULL`), + emailResendCount: int("email_resend_count").default(0), + emailChecked: tinyint("email_checked").default(0).notNull(), + gmsPublishEmail: tinyint("gms_publish_email").default(0).notNull(), + countryCode: varchar("country_code", { length: 255 }).default(sql`NULL`), + phone: varchar({ length: 255 }).default(sql`NULL`), + gmsPublishPhone: int("gms_publish_phone").default(0).notNull(), + createdAt: datetime("created_at", { mode: 'string', fsp: 3 }).default(sql`current_timestamp(3)`).notNull(), + updatedAt: datetime("updated_at", { mode: 'string', fsp: 3 }).default(sql`NULL`), + deletedAt: datetime("deleted_at", { mode: 'string', fsp: 3 }).default(sql`NULL`), +}, +(table) => [ + unique("email").on(table.email), + unique("email_verification_code").on(table.emailVerificationCode), +]); + +export const userRoles = mysqlTable("user_roles", { + id: int().autoincrement().notNull(), + userId: int("user_id").notNull(), + role: varchar({ length: 40 }).notNull(), + createdAt: datetime("created_at", { mode: 'string', fsp: 3 }).default(sql`current_timestamp(3)`).notNull(), + updatedAt: datetime("updated_at", { mode: 'string', fsp: 3 }).default(sql`NULL`), +}, +(table) => [ + index("user_id").on(table.userId), +]); diff --git a/database/src/queries/index.ts b/database/src/queries/index.ts index 0a7eb9ac3..93f0e95f1 100644 --- a/database/src/queries/index.ts +++ b/database/src/queries/index.ts @@ -5,6 +5,7 @@ export * from './communityHandshakes' export * from './events' export * from './openaiThreads' export * from './pendingTransactions' +export * from './projectBranding' export * from './transactionLinks' export * from './transactions' export * from './user' diff --git a/database/src/queries/projectBranding.ts b/database/src/queries/projectBranding.ts new file mode 100644 index 000000000..bee025efc --- /dev/null +++ b/database/src/queries/projectBranding.ts @@ -0,0 +1,50 @@ +import { eq } from 'drizzle-orm' +import { drizzleDb } from '../AppDatabase' +import { projectBrandingsTable } from '../schemas/drizzle.schema' + +export async function dbFindProjectSpaceUrl(alias: string): Promise { + const result = await drizzleDb() + .select({ spaceUrl: projectBrandingsTable.spaceUrl }) + .from(projectBrandingsTable) + .where(eq(projectBrandingsTable.alias, alias)) + .limit(1) + return result.at(0)?.spaceUrl +} +/** + * + * @param alias throw if project not found + * @returns logoUrl if project has logoUrl, else return null + */ + +export async function dbGetProjectLogoURL(alias: string): Promise { + const result = await drizzleDb() + .select({ logoUrl: projectBrandingsTable.logoUrl }) + .from(projectBrandingsTable) + .where(eq(projectBrandingsTable.alias, alias)) + .limit(1) + const firstEntry = result.at(0) + if (!firstEntry) { + throw new Error(`Project Branding with alias: ${alias} not found`) + } + return firstEntry.logoUrl +} + +export async function dbFindAllProjectBrandings(): Promise { + const result = await drizzleDb() + .select() + .from(projectBrandingsTable) + return result +} + +export async function dbFindProjectBrandingById(id: number): Promise { + const result = await drizzleDb() + .select() + .from(projectBrandingsTable) + .where(eq(projectBrandingsTable.id, id)) + .limit(1) + return result.at(0) +} + +export async function dbDeleteProjectBranding(id: number): Promise { + await drizzleDb().delete(projectBrandingsTable).where(eq(projectBrandingsTable.id, id)) +} \ No newline at end of file diff --git a/database/src/schemas/drizzle.schema.ts b/database/src/schemas/drizzle.schema.ts index 3dabc98e8..95435a9f3 100644 --- a/database/src/schemas/drizzle.schema.ts +++ b/database/src/schemas/drizzle.schema.ts @@ -1,4 +1,5 @@ -import { int, mysqlTable, timestamp, varchar } from 'drizzle-orm/mysql-core' +import { sql } from 'drizzle-orm' +import { int, mysqlTable, text, timestamp, tinyint, varchar } from 'drizzle-orm/mysql-core' export const openaiThreadsTable = mysqlTable('openai_threads', { id: varchar({ length: 128 }).notNull(), @@ -6,3 +7,14 @@ export const openaiThreadsTable = mysqlTable('openai_threads', { updatedAt: timestamp({ mode: 'date' }).defaultNow().onUpdateNow().notNull(), userId: int('user_id').notNull(), }) + +export const projectBrandingsTable = mysqlTable("project_brandings", { + id: int().autoincrement().notNull(), + name: varchar({ length: 255 }).notNull(), + alias: varchar({ length: 32 }).notNull(), + description: text().default(sql`NULL`), + spaceId: int("space_id").default(sql`NULL`), + spaceUrl: varchar("space_url", { length: 255 }).default(sql`NULL`), + newUserToSpace: tinyint("new_user_to_space").default(0).notNull(), + logoUrl: varchar("logo_url", { length: 255 }).default(sql`NULL`), +}) \ No newline at end of file