zoriya / Kyoo

A portable and vast media library solution.
https://kyoo.zoriya.dev
GNU General Public License v3.0
1.77k stars 43 forks source link

Support using Postgres database without public schema #536

Open acelinkio opened 5 months ago

acelinkio commented 5 months ago

Kyoo's version

4.6.0

What happened?

Unable to use database/user without public schema. The first pass of the migration container runs successfully and the application starts. However if the migration container runs again, it errors out with the following message.

Failed executing DbCommand (11ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
CREATE TABLE "__EFMigrationsHistory" (
    migration_id character varying(150) NOT NULL,
    product_version character varying(32) NOT NULL,
    CONSTRAINT pk___ef_migrations_history PRIMARY KEY (migration_id)
);
Npgsql.PostgresException (0x80004005): 42P07: relation "__EFMigrationsHistory" already exists
   at Npgsql.Internal.NpgsqlConnector.ReadMessageLong(Boolean async, DataRowLoadingMode dataRowLoadingMode, Boolean readingNotifications, Boolean isReadingPrependedMessage)
   at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming, CancellationToken cancellationToken)
   at Npgsql.NpgsqlDataReader.NextResult()
   at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteReader(Boolean async, CommandBehavior behavior, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery(Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteNonQuery()

When running using the public schema, migration container completes without error even on restart.

No migrations were applied. The database is already up to date.
Done.

example manifest

apiVersion: apps/v1
kind: Deployment
metadata:
  name: kyoo-back
  namespace: kyoo
  labels:
    app.kubernetes.io/component: back
    app.kubernetes.io/instance: kyoo
    app.kubernetes.io/name: kyoo
  annotations:
    reloader.stakater.com/auto: "true"
spec:
  replicas: 1
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app.kubernetes.io/component: back
      app.kubernetes.io/name: kyoo
      app.kubernetes.io/instance: kyoo
  template:
    metadata:
      labels:
        app.kubernetes.io/component: back
        app.kubernetes.io/instance: kyoo
        app.kubernetes.io/name: kyoo
    spec:
      initContainers:
        - env:
            - name: POSTGRES_USER
              value: datatestdb_owner_user
            - name: POSTGRES_PASSWORD
              value: REDACTED
            - name: POSTGRES_DB
              value: datatestdb
            - name: POSTGRES_SERVER
              value: cluster02.postgres
            - name: POSTGRES_PORT
              value: "5432"
          image: ghcr.io/zoriya/kyoo_migrations:edge
          name: postgres-migrations
      containers:
        - env:
            - name: TRANSCODER_URL
              value: http://transcoder.kyoo:7666
            - name: PUBLIC_URL
              value: http://localhost:8901
            - name: KYOO_APIKEYS
              value: REDACTED
            - name: POSTGRES_USER
              value: datatestdb_owner_user
            - name: POSTGRES_PASSWORD
              value: REDACTED
            - name: POSTGRES_DB
              value: datatestdb
            - name: POSTGRES_SERVER
              value: cluster02.postgres
            - name: POSTGRES_PORT
              value: "5432"
            - name: RABBITMQ_DEFAULT_USER
              value: default_user_EVdxzNQAcVY5ek6UO8B
            - name: RABBITMQ_DEFAULT_PASS
              value: REDACTED
            - name: RABBITMQ_HOST
              value: cluster01.rabbitmq
            - name: RABBITMQ_Port
              value: "5672"
            - name: MEILI_HOST
              value: http://meilisearch.kyoo:7700
            - name: MEILI_MASTER_KEY
              value: REDACTED
          image: ghcr.io/zoriya/kyoo_back:edge
          name: backend
          volumeMounts:
            - mountPath: /metadata
              name: backend
            - mountPath: /data
              name: media
              readOnly: true
              subPath: media
      volumes:
        - name: backend
          persistentVolumeClaim:
            claimName: backend
        - name: media
          persistentVolumeClaim:
            claimName: media
zoriya commented 3 months ago

the transcoder now uses it's own schema, the backend will be reworked in v5 (and won't use the public schema)