1
0
mirror of https://github.com/xuthus83/pigallery2.git synced 2025-01-14 14:43:17 +08:00

Fixing Database issue:

indexed text columns need a length. Replacing text with varchar.
simple-array is always text, so implementing custom array transformer
This commit is contained in:
Patrik J. Braun 2021-05-12 14:27:20 +02:00
parent 1d3f9df8f4
commit 96e8ec0d89
2 changed files with 24 additions and 9 deletions

View File

@ -1,4 +1,4 @@
import {Column, Entity, Index, ManyToOne, OneToMany, PrimaryGeneratedColumn, TableInheritance, Unique} from 'typeorm';
import {Column, Entity, Index, ManyToOne, OneToMany, PrimaryGeneratedColumn, TableInheritance, Unique, ValueTransformer} from 'typeorm';
import {DirectoryEntity} from './DirectoryEntity';
import {MediaDimension, MediaDTO, MediaMetadata} from '../../../../../common/entities/MediaDTO';
import {OrientationTypes} from 'ts-exif-parser';
@ -16,10 +16,15 @@ export class MediaDimensionEntity implements MediaDimension {
}
const arrayTransformer: ValueTransformer = {
to: (value: string[]): string => value ? value.join(',') : null,
from: (value: string): string[] => value ? value.split(',') : null
};
export class MediaMetadataEntity implements MediaMetadata {
@Index()
@Column('text')
@Column('varchar', {length: 128})
caption: string;
@Column(type => MediaDimensionEntity)
@ -43,7 +48,9 @@ export class MediaMetadataEntity implements MediaMetadata {
@Index()
@Column({
type: 'simple-array',
type: 'varchar',
length: 512,
transformer: arrayTransformer,
charset: columnCharsetCS.charset,
collation: columnCharsetCS.collation
})
@ -70,7 +77,10 @@ export class MediaMetadataEntity implements MediaMetadata {
*/
@Index()
@Column({
type: 'simple-array', select: false, nullable: true,
type: 'varchar',
select: false, nullable: true,
length: 512,
transformer: arrayTransformer,
charset: columnCharsetCS.charset,
collation: columnCharsetCS.collation
})

View File

@ -10,7 +10,8 @@ export class CameraMetadataEntity implements CameraMetadata {
@Column({
type: 'text', nullable: true,
type: 'varchar', nullable: true,
length: 64,
charset: columnCharsetCS.charset,
collation: columnCharsetCS.collation
})
@ -18,7 +19,8 @@ export class CameraMetadataEntity implements CameraMetadata {
@Column({
type: 'text', nullable: true,
type: 'varchar', nullable: true,
length: 64,
charset: columnCharsetCS.charset,
collation: columnCharsetCS.collation
})
@ -56,7 +58,8 @@ export class PositionMetaDataEntity implements PositionMetaData {
@Index()
@Column({
type: 'text', nullable: true,
type: 'varchar', nullable: true,
length: 64,
charset: columnCharsetCS.charset,
collation: columnCharsetCS.collation
})
@ -64,7 +67,8 @@ export class PositionMetaDataEntity implements PositionMetaData {
@Index()
@Column({
type: 'text', nullable: true,
type: 'varchar', nullable: true,
length: 64,
charset: columnCharsetCS.charset,
collation: columnCharsetCS.collation
})
@ -72,7 +76,8 @@ export class PositionMetaDataEntity implements PositionMetaData {
@Index()
@Column({
type: 'text', nullable: true,
type: 'varchar', nullable: true,
length: 64,
charset: columnCharsetCS.charset,
collation: columnCharsetCS.collation
})