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:
parent
1d3f9df8f4
commit
96e8ec0d89
@ -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 {DirectoryEntity} from './DirectoryEntity';
|
||||||
import {MediaDimension, MediaDTO, MediaMetadata} from '../../../../../common/entities/MediaDTO';
|
import {MediaDimension, MediaDTO, MediaMetadata} from '../../../../../common/entities/MediaDTO';
|
||||||
import {OrientationTypes} from 'ts-exif-parser';
|
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 {
|
export class MediaMetadataEntity implements MediaMetadata {
|
||||||
|
|
||||||
@Index()
|
@Index()
|
||||||
@Column('text')
|
@Column('varchar', {length: 128})
|
||||||
caption: string;
|
caption: string;
|
||||||
|
|
||||||
@Column(type => MediaDimensionEntity)
|
@Column(type => MediaDimensionEntity)
|
||||||
@ -43,7 +48,9 @@ export class MediaMetadataEntity implements MediaMetadata {
|
|||||||
|
|
||||||
@Index()
|
@Index()
|
||||||
@Column({
|
@Column({
|
||||||
type: 'simple-array',
|
type: 'varchar',
|
||||||
|
length: 512,
|
||||||
|
transformer: arrayTransformer,
|
||||||
charset: columnCharsetCS.charset,
|
charset: columnCharsetCS.charset,
|
||||||
collation: columnCharsetCS.collation
|
collation: columnCharsetCS.collation
|
||||||
})
|
})
|
||||||
@ -70,7 +77,10 @@ export class MediaMetadataEntity implements MediaMetadata {
|
|||||||
*/
|
*/
|
||||||
@Index()
|
@Index()
|
||||||
@Column({
|
@Column({
|
||||||
type: 'simple-array', select: false, nullable: true,
|
type: 'varchar',
|
||||||
|
select: false, nullable: true,
|
||||||
|
length: 512,
|
||||||
|
transformer: arrayTransformer,
|
||||||
charset: columnCharsetCS.charset,
|
charset: columnCharsetCS.charset,
|
||||||
collation: columnCharsetCS.collation
|
collation: columnCharsetCS.collation
|
||||||
})
|
})
|
||||||
|
@ -10,7 +10,8 @@ export class CameraMetadataEntity implements CameraMetadata {
|
|||||||
|
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
type: 'text', nullable: true,
|
type: 'varchar', nullable: true,
|
||||||
|
length: 64,
|
||||||
charset: columnCharsetCS.charset,
|
charset: columnCharsetCS.charset,
|
||||||
collation: columnCharsetCS.collation
|
collation: columnCharsetCS.collation
|
||||||
})
|
})
|
||||||
@ -18,7 +19,8 @@ export class CameraMetadataEntity implements CameraMetadata {
|
|||||||
|
|
||||||
|
|
||||||
@Column({
|
@Column({
|
||||||
type: 'text', nullable: true,
|
type: 'varchar', nullable: true,
|
||||||
|
length: 64,
|
||||||
charset: columnCharsetCS.charset,
|
charset: columnCharsetCS.charset,
|
||||||
collation: columnCharsetCS.collation
|
collation: columnCharsetCS.collation
|
||||||
})
|
})
|
||||||
@ -56,7 +58,8 @@ export class PositionMetaDataEntity implements PositionMetaData {
|
|||||||
|
|
||||||
@Index()
|
@Index()
|
||||||
@Column({
|
@Column({
|
||||||
type: 'text', nullable: true,
|
type: 'varchar', nullable: true,
|
||||||
|
length: 64,
|
||||||
charset: columnCharsetCS.charset,
|
charset: columnCharsetCS.charset,
|
||||||
collation: columnCharsetCS.collation
|
collation: columnCharsetCS.collation
|
||||||
})
|
})
|
||||||
@ -64,7 +67,8 @@ export class PositionMetaDataEntity implements PositionMetaData {
|
|||||||
|
|
||||||
@Index()
|
@Index()
|
||||||
@Column({
|
@Column({
|
||||||
type: 'text', nullable: true,
|
type: 'varchar', nullable: true,
|
||||||
|
length: 64,
|
||||||
charset: columnCharsetCS.charset,
|
charset: columnCharsetCS.charset,
|
||||||
collation: columnCharsetCS.collation
|
collation: columnCharsetCS.collation
|
||||||
})
|
})
|
||||||
@ -72,7 +76,8 @@ export class PositionMetaDataEntity implements PositionMetaData {
|
|||||||
|
|
||||||
@Index()
|
@Index()
|
||||||
@Column({
|
@Column({
|
||||||
type: 'text', nullable: true,
|
type: 'varchar', nullable: true,
|
||||||
|
length: 64,
|
||||||
charset: columnCharsetCS.charset,
|
charset: columnCharsetCS.charset,
|
||||||
collation: columnCharsetCS.collation
|
collation: columnCharsetCS.collation
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user