update postgres image for typeorm action

This commit is contained in:
mertalev 2023-11-22 23:15:15 -05:00
parent 90bc801c3e
commit d7d11429f4
No known key found for this signature in database
GPG key ID: 9181CD92C0A1C5E3
8 changed files with 30 additions and 27 deletions

View file

@ -213,7 +213,7 @@ jobs:
runs-on: ubuntu-latest
services:
postgres:
image: postgres@sha256:6dfee32131933ab4ca25a00360c3f427fdc134de56f9a90c6c9a4956b48aea85
image: tensorchord/pgvecto-rs:pg14-v0.1.10
env:
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres

View file

@ -29,6 +29,9 @@ export async function bootstrap() {
app.useStaticAssets('www');
app.use(indexFallback(excludePaths));
if (!dataSource.isInitialized) {
await dataSource.initialize();
}
await dataSource.query(`SET vectors.enable_prefilter = on`);
const server = await app.listen(port);

View file

@ -1,17 +1,17 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class UsePgVectors1699746198141 implements MigrationInterface {
name = 'UsePgVectors1699746198141';
export class UsePgVectors1700713871511 implements MigrationInterface {
name = 'UsePgVectors1700713871511';
public async up(queryRunner: QueryRunner): Promise<void> {
const faceDimQuery = await queryRunner.query(`
SELECT CARDINALITY(embedding::real[]) as dimsize
FROM asset_faces
LIMIT 1`);
SELECT CARDINALITY(embedding::real[]) as dimsize
FROM asset_faces
LIMIT 1`);
const clipDimQuery = await queryRunner.query(`
SELECT CARDINALITY("clipEmbedding"::real[]) as dimsize
FROM smart_info
LIMIT 1`);
SELECT CARDINALITY("clipEmbedding"::real[]) as dimsize
FROM smart_info
LIMIT 1`);
const faceDimSize = faceDimQuery?.[0]?.['dimsize'] ?? 512;
const clipDimSize = clipDimQuery?.[0]?.['dimsize'] ?? 512;
@ -20,17 +20,17 @@ export class UsePgVectors1699746198141 implements MigrationInterface {
await queryRunner.query('CREATE EXTENSION vectors');
await queryRunner.query(`
ALTER TABLE asset_faces
ALTER TABLE asset_faces
ALTER COLUMN embedding SET NOT NULL,
ALTER COLUMN embedding TYPE vector(${faceDimSize})`);
await queryRunner.query(`
CREATE TABLE smart_search (
CREATE TABLE smart_search (
"assetId" uuid PRIMARY KEY NOT NULL REFERENCES assets(id) ON DELETE CASCADE,
embedding vector(${clipDimSize}) NOT NULL )`);
await queryRunner.query(`
INSERT INTO smart_search("assetId", embedding)
INSERT INTO smart_search("assetId", embedding)
SELECT si."assetId", si."clipEmbedding"
FROM smart_info si
WHERE "clipEmbedding" IS NOT NULL`);
@ -40,11 +40,11 @@ export class UsePgVectors1699746198141 implements MigrationInterface {
await queryRunner.query(`ALTER TABLE asset_faces ALTER COLUMN embedding TYPE real array`);
await queryRunner.query(`ALTER TABLE smart_info ADD COLUMN IF NOT EXISTS "clipEmbedding" TYPE real array`);
await queryRunner.query(`
INSERT INTO smart_info
("assetId", "clipEmbedding")
SELECT s."assetId", s.embedding
FROM smart_search s
ON CONFLICT (s."assetId") DO UPDATE SET "clipEmbedding" = s.embedding`);
INSERT INTO smart_info
("assetId", "clipEmbedding")
SELECT s."assetId", s.embedding
FROM smart_search s
ON CONFLICT (s."assetId") DO UPDATE SET "clipEmbedding" = s.embedding`);
await queryRunner.query(`DROP TABLE IF EXISTS smart_search`);
await queryRunner.query('DROP EXTENSION IF EXISTS vectors');
}

View file

@ -1,7 +1,7 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddCLIPEmbeddingIndex1699746301742 implements MigrationInterface {
name = 'AddCLIPEmbeddingIndex1699746301742';
export class AddCLIPEmbeddingIndex1700713994428 implements MigrationInterface {
name = 'AddCLIPEmbeddingIndex1700713994428';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`

View file

@ -1,7 +1,7 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddFaceEmbeddingIndex1699746444644 implements MigrationInterface {
name = 'AddFaceEmbeddingIndex1699746444644';
export class AddFaceEmbeddingIndex1700714033632 implements MigrationInterface {
name = 'AddFaceEmbeddingIndex1700714033632';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`

View file

@ -1,7 +1,7 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddSmartInfoTagsIndex1699746328479 implements MigrationInterface {
name = 'AddSmartInfoTagsIndex1699746328479';
export class AddSmartInfoTagsIndex1700714072055 implements MigrationInterface {
name = 'AddSmartInfoTagsIndex1700714072055';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE INDEX IF NOT EXISTS si_tags ON smart_info USING GIN (tags);`);

View file

@ -1,7 +1,7 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class AddExifCityIndex1699746316571 implements MigrationInterface {
name = 'AddExifCityIndex1699746316571';
export class AddExifCityIndex1700714105178 implements MigrationInterface {
name = 'AddExifCityIndex1700714105178';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`CREATE INDEX IF NOT EXISTS exif_city ON exif (city);`);

View file

@ -1,7 +1,7 @@
import { MigrationInterface, QueryRunner } from 'typeorm';
export class CreateSmartInfoTextSearchIndex1696876192604 implements MigrationInterface {
name = 'CreateSmartInfoTextSearchIndex1696876192604';
export class CreateSmartInfoTextSearchIndex1700714140297 implements MigrationInterface {
name = 'CreateSmartInfoTextSearchIndex1700714140297';
public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`