mirror of
https://github.com/IT4Change/gradido.git
synced 2026-04-06 01:25:28 +00:00
add drizzle first import, add projectBranding to schema
This commit is contained in:
parent
f64b37b273
commit
b3e304efde
@ -1,9 +1,8 @@
|
|||||||
import { ProjectBranding } from 'database'
|
import { dbFindProjectSpaceUrl } from 'database'
|
||||||
import { SignJWT } from 'jose'
|
import { SignJWT } from 'jose'
|
||||||
import { getLogger } from 'log4js'
|
import { getLogger } from 'log4js'
|
||||||
import { IRequestOptions, IRestResponse, RestClient } from 'typed-rest-client'
|
import { IRequestOptions, IRestResponse, RestClient } from 'typed-rest-client'
|
||||||
import { CONFIG } from '@/config'
|
import { CONFIG } from '@/config'
|
||||||
|
|
||||||
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
|
import { LOG4JS_BASE_CATEGORY_NAME } from '@/config/const'
|
||||||
import { LogError } from '@/server/LogError'
|
import { LogError } from '@/server/LogError'
|
||||||
import { PostUserLoggingView } from './logging/PostUserLogging.view'
|
import { PostUserLoggingView } from './logging/PostUserLogging.view'
|
||||||
@ -67,15 +66,9 @@ export class HumHubClient {
|
|||||||
public async createAutoLoginUrl(username: string, project?: string | null) {
|
public async createAutoLoginUrl(username: string, project?: string | null) {
|
||||||
const secret = new TextEncoder().encode(CONFIG.HUMHUB_JWT_KEY)
|
const secret = new TextEncoder().encode(CONFIG.HUMHUB_JWT_KEY)
|
||||||
logger.info(`user ${username} as username for humhub auto-login`)
|
logger.info(`user ${username} as username for humhub auto-login`)
|
||||||
let redirectLink: string | undefined
|
let redirectLink: string | undefined | null
|
||||||
if (project) {
|
if (project) {
|
||||||
const projectBranding = await ProjectBranding.findOne({
|
redirectLink = await dbFindProjectSpaceUrl(project)
|
||||||
where: { alias: project },
|
|
||||||
select: { spaceUrl: true },
|
|
||||||
})
|
|
||||||
if (projectBranding?.spaceUrl) {
|
|
||||||
redirectLink = projectBranding.spaceUrl
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
const token = await new SignJWT({ username, redirectLink })
|
const token = await new SignJWT({ username, redirectLink })
|
||||||
.setProtectedHeader({ alg: 'HS256' })
|
.setProtectedHeader({ alg: 'HS256' })
|
||||||
|
|||||||
@ -1,9 +1,10 @@
|
|||||||
import { ProjectBranding as dbProjectBranding } from 'database'
|
import { projectBrandingsTable } from 'database'
|
||||||
import { Field, Int, ObjectType } from 'type-graphql'
|
import { Field, Int, ObjectType } from 'type-graphql'
|
||||||
|
|
||||||
@ObjectType()
|
@ObjectType()
|
||||||
export class ProjectBranding {
|
export class ProjectBranding {
|
||||||
constructor(projectBranding: dbProjectBranding) {
|
// TODO: replace with valibot schema
|
||||||
|
constructor(projectBranding: typeof projectBrandingsTable.$inferSelect) {
|
||||||
Object.assign(this, projectBranding)
|
Object.assign(this, projectBranding)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -2,7 +2,13 @@ import { ProjectBrandingInput } from '@input/ProjectBrandingInput'
|
|||||||
import { ProjectBranding } from '@model/ProjectBranding'
|
import { ProjectBranding } from '@model/ProjectBranding'
|
||||||
import { Space } from '@model/Space'
|
import { Space } from '@model/Space'
|
||||||
import { SpaceList } from '@model/SpaceList'
|
import { SpaceList } from '@model/SpaceList'
|
||||||
import { ProjectBranding as DbProjectBranding } from 'database'
|
import {
|
||||||
|
dbDeleteProjectBranding,
|
||||||
|
dbFindAllProjectBrandings,
|
||||||
|
dbFindProjectBrandingById,
|
||||||
|
dbGetProjectLogoURL,
|
||||||
|
projectBrandingsTable
|
||||||
|
} from 'database'
|
||||||
import { getLogger } from 'log4js'
|
import { getLogger } from 'log4js'
|
||||||
import { Arg, Authorized, ID, Int, Mutation, Query, Resolver } from 'type-graphql'
|
import { Arg, Authorized, ID, Int, Mutation, Query, Resolver } from 'type-graphql'
|
||||||
import { HumHubClient } from '@/apis/humhub/HumHubClient'
|
import { HumHubClient } from '@/apis/humhub/HumHubClient'
|
||||||
@ -17,15 +23,15 @@ export class ProjectBrandingResolver {
|
|||||||
@Query(() => [ProjectBranding])
|
@Query(() => [ProjectBranding])
|
||||||
@Authorized([RIGHTS.PROJECT_BRANDING_VIEW])
|
@Authorized([RIGHTS.PROJECT_BRANDING_VIEW])
|
||||||
async projectBrandings(): Promise<ProjectBranding[]> {
|
async projectBrandings(): Promise<ProjectBranding[]> {
|
||||||
return (await DbProjectBranding.find()).map(
|
return (await dbFindAllProjectBrandings()).map(
|
||||||
(entity: DbProjectBranding) => new ProjectBranding(entity),
|
(entity: typeof projectBrandingsTable.$inferSelect) => new ProjectBranding(entity),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Query(() => ProjectBranding)
|
@Query(() => ProjectBranding)
|
||||||
@Authorized([RIGHTS.PROJECT_BRANDING_VIEW])
|
@Authorized([RIGHTS.PROJECT_BRANDING_VIEW])
|
||||||
async projectBranding(@Arg('id', () => Int) id: number): Promise<ProjectBranding> {
|
async projectBranding(@Arg('id', () => Int) id: number): Promise<ProjectBranding> {
|
||||||
const projectBrandingEntity = await DbProjectBranding.findOneBy({ id })
|
const projectBrandingEntity = await dbFindProjectBrandingById(id)
|
||||||
if (!projectBrandingEntity) {
|
if (!projectBrandingEntity) {
|
||||||
throw new LogError(`Project Branding with id: ${id} not found`)
|
throw new LogError(`Project Branding with id: ${id} not found`)
|
||||||
}
|
}
|
||||||
@ -35,14 +41,7 @@ export class ProjectBrandingResolver {
|
|||||||
@Query(() => String, { nullable: true })
|
@Query(() => String, { nullable: true })
|
||||||
@Authorized([RIGHTS.PROJECT_BRANDING_BANNER])
|
@Authorized([RIGHTS.PROJECT_BRANDING_BANNER])
|
||||||
async projectBrandingBanner(@Arg('alias', () => String) alias: string): Promise<string | null> {
|
async projectBrandingBanner(@Arg('alias', () => String) alias: string): Promise<string | null> {
|
||||||
const projectBrandingEntity = await DbProjectBranding.findOne({
|
return await dbGetProjectLogoURL(alias)
|
||||||
where: { alias },
|
|
||||||
select: { id: true, logoUrl: true },
|
|
||||||
})
|
|
||||||
if (!projectBrandingEntity) {
|
|
||||||
throw new LogError(`Project Branding with alias: ${alias} not found`)
|
|
||||||
}
|
|
||||||
return projectBrandingEntity.logoUrl
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Mutation(() => ProjectBranding, { nullable: true })
|
@Mutation(() => ProjectBranding, { nullable: true })
|
||||||
@ -64,7 +63,7 @@ export class ProjectBrandingResolver {
|
|||||||
@Authorized([RIGHTS.PROJECT_BRANDING_MUTATE])
|
@Authorized([RIGHTS.PROJECT_BRANDING_MUTATE])
|
||||||
async deleteProjectBranding(@Arg('id', () => ID) id: number): Promise<boolean> {
|
async deleteProjectBranding(@Arg('id', () => ID) id: number): Promise<boolean> {
|
||||||
try {
|
try {
|
||||||
await DbProjectBranding.delete({ id })
|
await dbDeleteProjectBranding(id)
|
||||||
return true
|
return true
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
|
|||||||
303
database/drizzle/0000_unusual_the_order.sql
Normal file
303
database/drizzle/0000_unusual_the_order.sql
Normal file
@ -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`);
|
||||||
|
*/
|
||||||
2075
database/drizzle/meta/0000_snapshot.json
Normal file
2075
database/drizzle/meta/0000_snapshot.json
Normal file
File diff suppressed because it is too large
Load Diff
13
database/drizzle/meta/_journal.json
Normal file
13
database/drizzle/meta/_journal.json
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
{
|
||||||
|
"version": "7",
|
||||||
|
"dialect": "mysql",
|
||||||
|
"entries": [
|
||||||
|
{
|
||||||
|
"idx": 0,
|
||||||
|
"version": "5",
|
||||||
|
"when": 1763567731001,
|
||||||
|
"tag": "0000_unusual_the_order",
|
||||||
|
"breakpoints": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
321
database/drizzle/schema.ts
Normal file
321
database/drizzle/schema.ts
Normal file
@ -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),
|
||||||
|
]);
|
||||||
@ -5,6 +5,7 @@ export * from './communityHandshakes'
|
|||||||
export * from './events'
|
export * from './events'
|
||||||
export * from './openaiThreads'
|
export * from './openaiThreads'
|
||||||
export * from './pendingTransactions'
|
export * from './pendingTransactions'
|
||||||
|
export * from './projectBranding'
|
||||||
export * from './transactionLinks'
|
export * from './transactionLinks'
|
||||||
export * from './transactions'
|
export * from './transactions'
|
||||||
export * from './user'
|
export * from './user'
|
||||||
|
|||||||
50
database/src/queries/projectBranding.ts
Normal file
50
database/src/queries/projectBranding.ts
Normal file
@ -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<string | null | undefined> {
|
||||||
|
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<string | null> {
|
||||||
|
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<typeof projectBrandingsTable.$inferSelect[]> {
|
||||||
|
const result = await drizzleDb()
|
||||||
|
.select()
|
||||||
|
.from(projectBrandingsTable)
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function dbFindProjectBrandingById(id: number): Promise<typeof projectBrandingsTable.$inferSelect | undefined> {
|
||||||
|
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<void> {
|
||||||
|
await drizzleDb().delete(projectBrandingsTable).where(eq(projectBrandingsTable.id, id))
|
||||||
|
}
|
||||||
@ -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', {
|
export const openaiThreadsTable = mysqlTable('openai_threads', {
|
||||||
id: varchar({ length: 128 }).notNull(),
|
id: varchar({ length: 128 }).notNull(),
|
||||||
@ -6,3 +7,14 @@ export const openaiThreadsTable = mysqlTable('openai_threads', {
|
|||||||
updatedAt: timestamp({ mode: 'date' }).defaultNow().onUpdateNow().notNull(),
|
updatedAt: timestamp({ mode: 'date' }).defaultNow().onUpdateNow().notNull(),
|
||||||
userId: int('user_id').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`),
|
||||||
|
})
|
||||||
Loading…
x
Reference in New Issue
Block a user