From 715b28c3c06e74a102cc4f5e39f33ef39d796b28 Mon Sep 17 00:00:00 2001 From: dev Date: Tue, 8 Sep 2026 22:04:27 +0200 Subject: [PATCH] =?UTF-8?q?El=20cat=C3=A1logo=20de=20la=20base=20ya=20es?= =?UTF-8?q?=20id=C3=A9ntico=20al=20de=20los=20archivos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Antes de cambiar veinte rutas de sitio, poder demostrar que sale lo mismo. `npm run db:comparar` pone lado a lado las dieciocho canciones, los cuatro discos y los cuatro estilos, campo a campo, y dice dónde difieren con la ruta exacta —`dorina.registro.reparto[0].porcentaje`—. Confiar en que las pruebas de interfaz noten una diferencia de un año o de un porcentaje sería confiar de más: pintan lo que les den. La primera pasada encontró ciento y pico diferencias, y no eran del comparador: - **Ningún medio estaba enlazado.** El volcado del catálogo y el de archivos se hicieron por separado, así que las veintitrés canciones tenían `audio_id`, `muestra_id` y `portada_id` a nulo. La web habría dejado de reproducir en cuanto leyera de la base. No se vio al volcar porque aquello comprobaba las letras carácter a carácter —lo delicado— y no que las relaciones estuvieran puestas. - **Las etiquetas volvían en orden alfabético.** No es cosmético: la primera etiqueta de un tema dice de qué va y las de después matizan. Ahora `cancion_etiqueta` tiene `orden`. - **La nota de cada versión no tenía columna** donde caer. - El país de edición se guardaba en ninguna parte, y los cuatro discos se quedaron sin él. `scripts/db/completar-catalogo.mjs` ata esos cabos y es idempotente. Los alias de `medio` son de verdad y no la misma tabla dos veces: sin ellos Postgres devuelve la misma fila para el audio y para la portada. Co-Authored-By: Claude Opus 5 (1M context) --- ...9_nota_de_version_y_orden_de_etiquetas.sql | 11 + drizzle/meta/0009_snapshot.json | 6135 +++++++++++++++++ drizzle/meta/_journal.json | 7 + package.json | 4 +- scripts/db/comparar-catalogo.mjs | 145 + scripts/db/completar-catalogo.mjs | 226 + scripts/db/env-privado.mjs | 8 + scripts/db/gancho-lib.mjs | 3 +- src/lib/server/catalogo.ts | 371 + src/lib/server/db/schema/catalogo.ts | 10 +- 10 files changed, 6917 insertions(+), 3 deletions(-) create mode 100644 drizzle/0009_nota_de_version_y_orden_de_etiquetas.sql create mode 100644 drizzle/meta/0009_snapshot.json create mode 100644 scripts/db/comparar-catalogo.mjs create mode 100644 scripts/db/completar-catalogo.mjs create mode 100644 scripts/db/env-privado.mjs create mode 100644 src/lib/server/catalogo.ts diff --git a/drizzle/0009_nota_de_version_y_orden_de_etiquetas.sql b/drizzle/0009_nota_de_version_y_orden_de_etiquetas.sql new file mode 100644 index 0000000..a7b576f --- /dev/null +++ b/drizzle/0009_nota_de_version_y_orden_de_etiquetas.sql @@ -0,0 +1,11 @@ +-- Dos columnas que faltaban, y que se vieron comparando. +-- +-- El comparador de la fase 4 pone lado a lado el catálogo del archivo y el de +-- la base, campo a campo. Salió que la nota de cada versión —«Voz y guitarra, +-- grabada en el salón de casa»— no tenía columna donde caer, y que las +-- etiquetas volvían en orden alfabético y no en el que se escribieron. Lo +-- segundo no es cosmético: la primera etiqueta de un tema dice de qué va, y +-- las de después matizan. + +ALTER TABLE "cancion" ADD COLUMN "version_nota" text;--> statement-breakpoint +ALTER TABLE "cancion_etiqueta" ADD COLUMN "orden" integer DEFAULT 0 NOT NULL; \ No newline at end of file diff --git a/drizzle/meta/0009_snapshot.json b/drizzle/meta/0009_snapshot.json new file mode 100644 index 0000000..bdeebe6 --- /dev/null +++ b/drizzle/meta/0009_snapshot.json @@ -0,0 +1,6135 @@ +{ + "id": "561b8b58-0261-4c3f-a232-d1c6432189d2", + "prevId": "8c17f18b-5da7-41b2-893b-2c6a5055acd9", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.medio": { + "name": "medio", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "clase": { + "name": "clase", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "clave": { + "name": "clave", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "publico": { + "name": "publico", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "mime": { + "name": "mime", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "bytes": { + "name": "bytes", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "duracion_s": { + "name": "duracion_s", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "ancho": { + "name": "ancho", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "alto": { + "name": "alto", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "sha256": { + "name": "sha256", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "alt": { + "name": "alt", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "medio_clase": { + "name": "medio_clase", + "columns": [ + { + "expression": "clase", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "medio_sha": { + "name": "medio_sha", + "columns": [ + { + "expression": "sha256", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "medio_clave_unique": { + "name": "medio_clave_unique", + "nullsNotDistinct": false, + "columns": [ + "clave" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pais": { + "name": "pais", + "schema": "", + "columns": { + "codigo": { + "name": "codigo", + "type": "char(2)", + "primaryKey": true, + "notNull": true + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "gentilicio": { + "name": "gentilicio", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "region": { + "name": "region", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.persona": { + "name": "persona", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nombre_legal": { + "name": "nombre_legal", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ipi": { + "name": "ipi", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "nacimiento": { + "name": "nacimiento", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "defuncion": { + "name": "defuncion", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "pais_codigo": { + "name": "pais_codigo", + "type": "char(2)", + "primaryKey": false, + "notNull": false + }, + "retrato_id": { + "name": "retrato_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "semblanza": { + "name": "semblanza", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "estado": { + "name": "estado", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'borrador'" + }, + "origen": { + "name": "origen", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "modelo_origen": { + "name": "modelo_origen", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "importado_en": { + "name": "importado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "revisado_por": { + "name": "revisado_por", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "revisado_en": { + "name": "revisado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "actualizado_en": { + "name": "actualizado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "persona_nombre": { + "name": "persona_nombre", + "columns": [ + { + "expression": "nombre", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "persona_pais": { + "name": "persona_pais", + "columns": [ + { + "expression": "pais_codigo", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "persona_pais_codigo_pais_codigo_fk": { + "name": "persona_pais_codigo_pais_codigo_fk", + "tableFrom": "persona", + "tableTo": "pais", + "columnsFrom": [ + "pais_codigo" + ], + "columnsTo": [ + "codigo" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "persona_retrato_id_medio_id_fk": { + "name": "persona_retrato_id_medio_id_fk", + "tableFrom": "persona", + "tableTo": "medio", + "columnsFrom": [ + "retrato_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "persona_slug_unique": { + "name": "persona_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.album": { + "name": "album", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "titulo": { + "name": "titulo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "estilo_id": { + "name": "estilo_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tipo": { + "name": "tipo", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'album'" + }, + "fecha": { + "name": "fecha", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "portada_id": { + "name": "portada_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sello": { + "name": "sello", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "resumen": { + "name": "resumen", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "destacado": { + "name": "destacado", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "numero_catalogo": { + "name": "numero_catalogo", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "formatos": { + "name": "formatos", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "pais_edicion_codigo": { + "name": "pais_edicion_codigo", + "type": "char(2)", + "primaryKey": false, + "notNull": false + }, + "estado": { + "name": "estado", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'borrador'" + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "actualizado_en": { + "name": "actualizado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "album_estilo": { + "name": "album_estilo", + "columns": [ + { + "expression": "estilo_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "album_fecha": { + "name": "album_fecha", + "columns": [ + { + "expression": "fecha", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "album_estilo_id_estilo_id_fk": { + "name": "album_estilo_id_estilo_id_fk", + "tableFrom": "album", + "tableTo": "estilo", + "columnsFrom": [ + "estilo_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "album_portada_id_medio_id_fk": { + "name": "album_portada_id_medio_id_fk", + "tableFrom": "album", + "tableTo": "medio", + "columnsFrom": [ + "portada_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "album_pais_edicion_codigo_pais_codigo_fk": { + "name": "album_pais_edicion_codigo_pais_codigo_fk", + "tableFrom": "album", + "tableTo": "pais", + "columnsFrom": [ + "pais_edicion_codigo" + ], + "columnsTo": [ + "codigo" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "album_slug_unique": { + "name": "album_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.album_enlace": { + "name": "album_enlace", + "schema": "", + "columns": { + "album_id": { + "name": "album_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "plataforma": { + "name": "plataforma", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "album_enlace_album_id_album_id_fk": { + "name": "album_enlace_album_id_album_id_fk", + "tableFrom": "album_enlace", + "tableTo": "album", + "columnsFrom": [ + "album_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "album_enlace_album_id_plataforma_pk": { + "name": "album_enlace_album_id_plataforma_pk", + "columns": [ + "album_id", + "plataforma" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.autoria": { + "name": "autoria", + "schema": "", + "columns": { + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "persona_id": { + "name": "persona_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "rol": { + "name": "rol", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "porcentaje": { + "name": "porcentaje", + "type": "numeric(5, 2)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "autoria_cancion_id_cancion_id_fk": { + "name": "autoria_cancion_id_cancion_id_fk", + "tableFrom": "autoria", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "autoria_persona_id_persona_id_fk": { + "name": "autoria_persona_id_persona_id_fk", + "tableFrom": "autoria", + "tableTo": "persona", + "columnsFrom": [ + "persona_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "autoria_cancion_id_persona_id_rol_pk": { + "name": "autoria_cancion_id_persona_id_rol_pk", + "columns": [ + "cancion_id", + "persona_id", + "rol" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cancion": { + "name": "cancion", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "titulo": { + "name": "titulo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version_de_id": { + "name": "version_de_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version_nombre": { + "name": "version_nombre", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version_nota": { + "name": "version_nota", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "version_orden": { + "name": "version_orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "estilo_id": { + "name": "estilo_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "album_id": { + "name": "album_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "numero": { + "name": "numero", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "audio_id": { + "name": "audio_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "muestra_id": { + "name": "muestra_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "duracion_s": { + "name": "duracion_s", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "ano": { + "name": "ano", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "letra": { + "name": "letra", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "idioma": { + "name": "idioma", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'es'" + }, + "inspiracion": { + "name": "inspiracion", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "instrumental": { + "name": "instrumental", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "destacada": { + "name": "destacada", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "portada_id": { + "name": "portada_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ala_venta": { + "name": "ala_venta", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "estado": { + "name": "estado", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'borrador'" + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "actualizado_en": { + "name": "actualizado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "cancion_estilo": { + "name": "cancion_estilo", + "columns": [ + { + "expression": "estilo_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "cancion_album": { + "name": "cancion_album", + "columns": [ + { + "expression": "album_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "cancion_version_de": { + "name": "cancion_version_de", + "columns": [ + { + "expression": "version_de_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "cancion_destacada": { + "name": "cancion_destacada", + "columns": [ + { + "expression": "destacada", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "cancion_estilo_id_estilo_id_fk": { + "name": "cancion_estilo_id_estilo_id_fk", + "tableFrom": "cancion", + "tableTo": "estilo", + "columnsFrom": [ + "estilo_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "cancion_album_id_album_id_fk": { + "name": "cancion_album_id_album_id_fk", + "tableFrom": "cancion", + "tableTo": "album", + "columnsFrom": [ + "album_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "cancion_audio_id_medio_id_fk": { + "name": "cancion_audio_id_medio_id_fk", + "tableFrom": "cancion", + "tableTo": "medio", + "columnsFrom": [ + "audio_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "cancion_muestra_id_medio_id_fk": { + "name": "cancion_muestra_id_medio_id_fk", + "tableFrom": "cancion", + "tableTo": "medio", + "columnsFrom": [ + "muestra_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "cancion_portada_id_medio_id_fk": { + "name": "cancion_portada_id_medio_id_fk", + "tableFrom": "cancion", + "tableTo": "medio", + "columnsFrom": [ + "portada_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "cancion_slug_unique": { + "name": "cancion_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cancion_enlace": { + "name": "cancion_enlace", + "schema": "", + "columns": { + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "plataforma": { + "name": "plataforma", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "cancion_enlace_cancion_id_cancion_id_fk": { + "name": "cancion_enlace_cancion_id_cancion_id_fk", + "tableFrom": "cancion_enlace", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "cancion_enlace_cancion_id_plataforma_pk": { + "name": "cancion_enlace_cancion_id_plataforma_pk", + "columns": [ + "cancion_id", + "plataforma" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cancion_etiqueta": { + "name": "cancion_etiqueta", + "schema": "", + "columns": { + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "etiqueta_id": { + "name": "etiqueta_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "cancion_etiqueta_cancion_id_cancion_id_fk": { + "name": "cancion_etiqueta_cancion_id_cancion_id_fk", + "tableFrom": "cancion_etiqueta", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cancion_etiqueta_etiqueta_id_etiqueta_id_fk": { + "name": "cancion_etiqueta_etiqueta_id_etiqueta_id_fk", + "tableFrom": "cancion_etiqueta", + "tableTo": "etiqueta", + "columnsFrom": [ + "etiqueta_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "cancion_etiqueta_cancion_id_etiqueta_id_pk": { + "name": "cancion_etiqueta_cancion_id_etiqueta_id_pk", + "columns": [ + "cancion_id", + "etiqueta_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cancion_persona": { + "name": "cancion_persona", + "schema": "", + "columns": { + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "persona_id": { + "name": "persona_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "rol": { + "name": "rol", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "cancion_persona_cancion_id_cancion_id_fk": { + "name": "cancion_persona_cancion_id_cancion_id_fk", + "tableFrom": "cancion_persona", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cancion_persona_persona_id_persona_id_fk": { + "name": "cancion_persona_persona_id_persona_id_fk", + "tableFrom": "cancion_persona", + "tableTo": "persona", + "columnsFrom": [ + "persona_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "cancion_persona_cancion_id_persona_id_rol_pk": { + "name": "cancion_persona_cancion_id_persona_id_rol_pk", + "columns": [ + "cancion_id", + "persona_id", + "rol" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.credito_album": { + "name": "credito_album", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "album_id": { + "name": "album_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "persona_id": { + "name": "persona_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rol": { + "name": "rol", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": { + "credito_album_album": { + "name": "credito_album_album", + "columns": [ + { + "expression": "album_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "credito_album_album_id_album_id_fk": { + "name": "credito_album_album_id_album_id_fk", + "tableFrom": "credito_album", + "tableTo": "album", + "columnsFrom": [ + "album_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "credito_album_persona_id_persona_id_fk": { + "name": "credito_album_persona_id_persona_id_fk", + "tableFrom": "credito_album", + "tableTo": "persona", + "columnsFrom": [ + "persona_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.estilo": { + "name": "estilo", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resumen": { + "name": "resumen", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "principal": { + "name": "principal", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "imagen_id": { + "name": "imagen_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "estado": { + "name": "estado", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'borrador'" + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "actualizado_en": { + "name": "actualizado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "estilo_principal_unico": { + "name": "estilo_principal_unico", + "columns": [ + { + "expression": "principal", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"estilo\".\"principal\"", + "concurrently": false, + "method": "btree", + "with": {} + }, + "estilo_orden": { + "name": "estilo_orden", + "columns": [ + { + "expression": "orden", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "estilo_imagen_id_medio_id_fk": { + "name": "estilo_imagen_id_medio_id_fk", + "tableFrom": "estilo", + "tableTo": "medio", + "columnsFrom": [ + "imagen_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "estilo_slug_unique": { + "name": "estilo_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.etiqueta": { + "name": "etiqueta", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "etiqueta_slug_unique": { + "name": "etiqueta_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.registro_obra": { + "name": "registro_obra", + "schema": "", + "columns": { + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "iswc": { + "name": "iswc", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "isrc": { + "name": "isrc", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "entidad": { + "name": "entidad", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "numero": { + "name": "numero", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "editorial": { + "name": "editorial", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "registro_obra_cancion_id_cancion_id_fk": { + "name": "registro_obra_cancion_id_cancion_id_fk", + "tableFrom": "registro_obra", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.traduccion": { + "name": "traduccion", + "schema": "", + "columns": { + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "idioma": { + "name": "idioma", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "texto": { + "name": "texto", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "traduccion_cancion_id_cancion_id_fk": { + "name": "traduccion_cancion_id_cancion_id_fk", + "tableFrom": "traduccion", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "traduccion_cancion_id_idioma_pk": { + "name": "traduccion_cancion_id_idioma_pk", + "columns": [ + "cancion_id", + "idioma" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.video": { + "name": "video", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "youtube_id": { + "name": "youtube_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "titulo": { + "name": "titulo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": { + "video_cancion": { + "name": "video_cancion", + "columns": [ + { + "expression": "cancion_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "video_cancion_id_cancion_id_fk": { + "name": "video_cancion_id_cancion_id_fk", + "tableFrom": "video", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.acepcion": { + "name": "acepcion", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "termino_id": { + "name": "termino_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "numero": { + "name": "numero", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "categoria": { + "name": "categoria", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "definicion": { + "name": "definicion", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "ampliacion": { + "name": "ampliacion", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ejemplo": { + "name": "ejemplo", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "acepcion_numero": { + "name": "acepcion_numero", + "columns": [ + { + "expression": "termino_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "numero", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "acepcion_termino_id_termino_id_fk": { + "name": "acepcion_termino_id_termino_id_fk", + "tableFrom": "acepcion", + "tableTo": "termino", + "columnsFrom": [ + "termino_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.animo": { + "name": "animo", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "codigo": { + "name": "codigo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "gems": { + "name": "gems", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "valencia": { + "name": "valencia", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "energia": { + "name": "energia", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "descripcion": { + "name": "descripcion", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "animo_codigo_unique": { + "name": "animo_codigo_unique", + "nullsNotDistinct": false, + "columns": [ + "codigo" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.cancion_genero": { + "name": "cancion_genero", + "schema": "", + "columns": { + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "genero_id": { + "name": "genero_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "cancion_genero_cancion_id_cancion_id_fk": { + "name": "cancion_genero_cancion_id_cancion_id_fk", + "tableFrom": "cancion_genero", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "cancion_genero_genero_id_genero_id_fk": { + "name": "cancion_genero_genero_id_genero_id_fk", + "tableFrom": "cancion_genero", + "tableTo": "genero", + "columnsFrom": [ + "genero_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "cancion_genero_cancion_id_genero_id_pk": { + "name": "cancion_genero_cancion_id_genero_id_pk", + "columns": [ + "cancion_id", + "genero_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.capitulo": { + "name": "capitulo", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "titulo": { + "name": "titulo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tipo": { + "name": "tipo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "genero_id": { + "name": "genero_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "resumen": { + "name": "resumen", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "cuerpo": { + "name": "cuerpo", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "estado": { + "name": "estado", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'borrador'" + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "actualizado_en": { + "name": "actualizado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "capitulo_tipo": { + "name": "capitulo_tipo", + "columns": [ + { + "expression": "tipo", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "orden", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "capitulo_genero_id_genero_id_fk": { + "name": "capitulo_genero_id_genero_id_fk", + "tableFrom": "capitulo", + "tableTo": "genero", + "columnsFrom": [ + "genero_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "capitulo_slug_unique": { + "name": "capitulo_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.capitulo_acepcion": { + "name": "capitulo_acepcion", + "schema": "", + "columns": { + "capitulo_id": { + "name": "capitulo_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "acepcion_id": { + "name": "acepcion_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "automatico": { + "name": "automatico", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "confirmado": { + "name": "confirmado", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": {}, + "foreignKeys": { + "capitulo_acepcion_capitulo_id_capitulo_id_fk": { + "name": "capitulo_acepcion_capitulo_id_capitulo_id_fk", + "tableFrom": "capitulo_acepcion", + "tableTo": "capitulo", + "columnsFrom": [ + "capitulo_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "capitulo_acepcion_acepcion_id_acepcion_id_fk": { + "name": "capitulo_acepcion_acepcion_id_acepcion_id_fk", + "tableFrom": "capitulo_acepcion", + "tableTo": "acepcion", + "columnsFrom": [ + "acepcion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "capitulo_acepcion_capitulo_id_acepcion_id_pk": { + "name": "capitulo_acepcion_capitulo_id_acepcion_id_pk", + "columns": [ + "capitulo_id", + "acepcion_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.compas": { + "name": "compas", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "codigo": { + "name": "codigo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "numerador": { + "name": "numerador", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "denominador": { + "name": "denominador", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "nota": { + "name": "nota", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "compas_codigo_unique": { + "name": "compas_codigo_unique", + "nullsNotDistinct": false, + "columns": [ + "codigo" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.genero": { + "name": "genero", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resumen": { + "name": "resumen", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "origen_lugar": { + "name": "origen_lugar", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "origen_ano": { + "name": "origen_ano", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "tempo": { + "name": "tempo", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rima": { + "name": "rima", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "metrica_nota": { + "name": "metrica_nota", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "compas_nota": { + "name": "compas_nota", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rasgos": { + "name": "rasgos", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "estado": { + "name": "estado", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'borrador'" + }, + "origen": { + "name": "origen", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "modelo_origen": { + "name": "modelo_origen", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "importado_en": { + "name": "importado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "revisado_por": { + "name": "revisado_por", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "revisado_en": { + "name": "revisado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "actualizado_en": { + "name": "actualizado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "genero_nombre": { + "name": "genero_nombre", + "columns": [ + { + "expression": "nombre", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "genero_origen_ano": { + "name": "genero_origen_ano", + "columns": [ + { + "expression": "origen_ano", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "genero_slug_unique": { + "name": "genero_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.genero_alias": { + "name": "genero_alias", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "genero_id": { + "name": "genero_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pais_codigo": { + "name": "pais_codigo", + "type": "char(2)", + "primaryKey": false, + "notNull": false + }, + "nota": { + "name": "nota", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "genero_alias_nombre": { + "name": "genero_alias_nombre", + "columns": [ + { + "expression": "nombre", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "genero_alias_genero_id_genero_id_fk": { + "name": "genero_alias_genero_id_genero_id_fk", + "tableFrom": "genero_alias", + "tableTo": "genero", + "columnsFrom": [ + "genero_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "genero_alias_pais_codigo_pais_codigo_fk": { + "name": "genero_alias_pais_codigo_pais_codigo_fk", + "tableFrom": "genero_alias", + "tableTo": "pais", + "columnsFrom": [ + "pais_codigo" + ], + "columnsTo": [ + "codigo" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.genero_compas": { + "name": "genero_compas", + "schema": "", + "columns": { + "genero_id": { + "name": "genero_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "compas_id": { + "name": "compas_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "principal": { + "name": "principal", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "nota": { + "name": "nota", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "genero_compas_genero_id_genero_id_fk": { + "name": "genero_compas_genero_id_genero_id_fk", + "tableFrom": "genero_compas", + "tableTo": "genero", + "columnsFrom": [ + "genero_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "genero_compas_compas_id_compas_id_fk": { + "name": "genero_compas_compas_id_compas_id_fk", + "tableFrom": "genero_compas", + "tableTo": "compas", + "columnsFrom": [ + "compas_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "genero_compas_genero_id_compas_id_pk": { + "name": "genero_compas_genero_id_compas_id_pk", + "columns": [ + "genero_id", + "compas_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.genero_instrumento": { + "name": "genero_instrumento", + "schema": "", + "columns": { + "genero_id": { + "name": "genero_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "instrumento_id": { + "name": "instrumento_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "importancia": { + "name": "importancia", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'habitual'" + }, + "papel": { + "name": "papel", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "genero_instrumento_genero_id_genero_id_fk": { + "name": "genero_instrumento_genero_id_genero_id_fk", + "tableFrom": "genero_instrumento", + "tableTo": "genero", + "columnsFrom": [ + "genero_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "genero_instrumento_instrumento_id_instrumento_id_fk": { + "name": "genero_instrumento_instrumento_id_instrumento_id_fk", + "tableFrom": "genero_instrumento", + "tableTo": "instrumento", + "columnsFrom": [ + "instrumento_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "genero_instrumento_genero_id_instrumento_id_pk": { + "name": "genero_instrumento_genero_id_instrumento_id_pk", + "columns": [ + "genero_id", + "instrumento_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.genero_metro": { + "name": "genero_metro", + "schema": "", + "columns": { + "genero_id": { + "name": "genero_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "metro_id": { + "name": "metro_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "predominante": { + "name": "predominante", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": {}, + "foreignKeys": { + "genero_metro_genero_id_genero_id_fk": { + "name": "genero_metro_genero_id_genero_id_fk", + "tableFrom": "genero_metro", + "tableTo": "genero", + "columnsFrom": [ + "genero_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "genero_metro_metro_id_metro_id_fk": { + "name": "genero_metro_metro_id_metro_id_fk", + "tableFrom": "genero_metro", + "tableTo": "metro", + "columnsFrom": [ + "metro_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "genero_metro_genero_id_metro_id_pk": { + "name": "genero_metro_genero_id_metro_id_pk", + "columns": [ + "genero_id", + "metro_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.genero_origen": { + "name": "genero_origen", + "schema": "", + "columns": { + "genero_id": { + "name": "genero_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "origen_id": { + "name": "origen_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tipo": { + "name": "tipo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "principal": { + "name": "principal", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "nota": { + "name": "nota", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": { + "genero_origen_origen": { + "name": "genero_origen_origen", + "columns": [ + { + "expression": "origen_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "genero_origen_genero_id_genero_id_fk": { + "name": "genero_origen_genero_id_genero_id_fk", + "tableFrom": "genero_origen", + "tableTo": "genero", + "columnsFrom": [ + "genero_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "genero_origen_origen_id_genero_id_fk": { + "name": "genero_origen_origen_id_genero_id_fk", + "tableFrom": "genero_origen", + "tableTo": "genero", + "columnsFrom": [ + "origen_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "genero_origen_genero_id_origen_id_tipo_pk": { + "name": "genero_origen_genero_id_origen_id_tipo_pk", + "columns": [ + "genero_id", + "origen_id", + "tipo" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.genero_pais": { + "name": "genero_pais", + "schema": "", + "columns": { + "genero_id": { + "name": "genero_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pais_codigo": { + "name": "pais_codigo", + "type": "char(2)", + "primaryKey": false, + "notNull": true + }, + "relacion": { + "name": "relacion", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'adoptado'" + }, + "nota": { + "name": "nota", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "genero_pais_genero_id_genero_id_fk": { + "name": "genero_pais_genero_id_genero_id_fk", + "tableFrom": "genero_pais", + "tableTo": "genero", + "columnsFrom": [ + "genero_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "genero_pais_pais_codigo_pais_codigo_fk": { + "name": "genero_pais_pais_codigo_pais_codigo_fk", + "tableFrom": "genero_pais", + "tableTo": "pais", + "columnsFrom": [ + "pais_codigo" + ], + "columnsTo": [ + "codigo" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "genero_pais_genero_id_pais_codigo_pk": { + "name": "genero_pais_genero_id_pais_codigo_pk", + "columns": [ + "genero_id", + "pais_codigo" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.genero_persona": { + "name": "genero_persona", + "schema": "", + "columns": { + "genero_id": { + "name": "genero_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "persona_id": { + "name": "persona_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "papel": { + "name": "papel", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nota": { + "name": "nota", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "genero_persona_genero_id_genero_id_fk": { + "name": "genero_persona_genero_id_genero_id_fk", + "tableFrom": "genero_persona", + "tableTo": "genero", + "columnsFrom": [ + "genero_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "genero_persona_persona_id_persona_id_fk": { + "name": "genero_persona_persona_id_persona_id_fk", + "tableFrom": "genero_persona", + "tableTo": "persona", + "columnsFrom": [ + "persona_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "genero_persona_genero_id_persona_id_papel_pk": { + "name": "genero_persona_genero_id_persona_id_papel_pk", + "columns": [ + "genero_id", + "persona_id", + "papel" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.genero_seccion": { + "name": "genero_seccion", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "genero_id": { + "name": "genero_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "clave": { + "name": "clave", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "titulo": { + "name": "titulo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cuerpo": { + "name": "cuerpo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": { + "genero_seccion_clave": { + "name": "genero_seccion_clave", + "columns": [ + { + "expression": "genero_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "clave", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "genero_seccion_genero_id_genero_id_fk": { + "name": "genero_seccion_genero_id_genero_id_fk", + "tableFrom": "genero_seccion", + "tableTo": "genero", + "columnsFrom": [ + "genero_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.genero_tema": { + "name": "genero_tema", + "schema": "", + "columns": { + "genero_id": { + "name": "genero_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "etiqueta_id": { + "name": "etiqueta_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "genero_tema_genero_id_genero_id_fk": { + "name": "genero_tema_genero_id_genero_id_fk", + "tableFrom": "genero_tema", + "tableTo": "genero", + "columnsFrom": [ + "genero_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "genero_tema_etiqueta_id_etiqueta_id_fk": { + "name": "genero_tema_etiqueta_id_etiqueta_id_fk", + "tableFrom": "genero_tema", + "tableTo": "etiqueta", + "columnsFrom": [ + "etiqueta_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "genero_tema_genero_id_etiqueta_id_pk": { + "name": "genero_tema_genero_id_etiqueta_id_pk", + "columns": [ + "genero_id", + "etiqueta_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.instrumento": { + "name": "instrumento", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "familia": { + "name": "familia", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "subfamilia": { + "name": "subfamilia", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pais_codigo": { + "name": "pais_codigo", + "type": "char(2)", + "primaryKey": false, + "notNull": false + }, + "descripcion": { + "name": "descripcion", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "afinacion": { + "name": "afinacion", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "imagen_id": { + "name": "imagen_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "muestra_id": { + "name": "muestra_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "estado": { + "name": "estado", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'borrador'" + }, + "origen": { + "name": "origen", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "modelo_origen": { + "name": "modelo_origen", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "importado_en": { + "name": "importado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "revisado_por": { + "name": "revisado_por", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "revisado_en": { + "name": "revisado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "instrumento_familia": { + "name": "instrumento_familia", + "columns": [ + { + "expression": "familia", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "instrumento_pais_codigo_pais_codigo_fk": { + "name": "instrumento_pais_codigo_pais_codigo_fk", + "tableFrom": "instrumento", + "tableTo": "pais", + "columnsFrom": [ + "pais_codigo" + ], + "columnsTo": [ + "codigo" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "instrumento_imagen_id_medio_id_fk": { + "name": "instrumento_imagen_id_medio_id_fk", + "tableFrom": "instrumento", + "tableTo": "medio", + "columnsFrom": [ + "imagen_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "instrumento_muestra_id_medio_id_fk": { + "name": "instrumento_muestra_id_medio_id_fk", + "tableFrom": "instrumento", + "tableTo": "medio", + "columnsFrom": [ + "muestra_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "instrumento_slug_unique": { + "name": "instrumento_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.metro": { + "name": "metro", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "codigo": { + "name": "codigo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "silabas": { + "name": "silabas", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "termino_id": { + "name": "termino_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "nota": { + "name": "nota", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "metro_codigo_unique": { + "name": "metro_codigo_unique", + "nullsNotDistinct": false, + "columns": [ + "codigo" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.modelo_ia": { + "name": "modelo_ia", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "codigo": { + "name": "codigo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "familia": { + "name": "familia", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "version": { + "name": "version", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "vigente": { + "name": "vigente", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "nota_sintaxis": { + "name": "nota_sintaxis", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "esquema": { + "name": "esquema", + "type": "jsonb", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "modelo_ia_familia": { + "name": "modelo_ia_familia", + "columns": [ + { + "expression": "familia", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "modelo_ia_codigo_unique": { + "name": "modelo_ia_codigo_unique", + "nullsNotDistinct": false, + "columns": [ + "codigo" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.obra_referencia": { + "name": "obra_referencia", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "titulo": { + "name": "titulo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "ano": { + "name": "ano", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "genero_id": { + "name": "genero_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "nota": { + "name": "nota", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cita": { + "name": "cita", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "estado": { + "name": "estado", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'borrador'" + }, + "origen": { + "name": "origen", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "modelo_origen": { + "name": "modelo_origen", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "importado_en": { + "name": "importado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "revisado_por": { + "name": "revisado_por", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "revisado_en": { + "name": "revisado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "obra_referencia_genero": { + "name": "obra_referencia_genero", + "columns": [ + { + "expression": "genero_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "obra_referencia_genero_id_genero_id_fk": { + "name": "obra_referencia_genero_id_genero_id_fk", + "tableFrom": "obra_referencia", + "tableTo": "genero", + "columnsFrom": [ + "genero_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "obra_referencia_slug_unique": { + "name": "obra_referencia_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.obra_referencia_enlace": { + "name": "obra_referencia_enlace", + "schema": "", + "columns": { + "obra_id": { + "name": "obra_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "plataforma": { + "name": "plataforma", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "obra_referencia_enlace_obra_id_obra_referencia_id_fk": { + "name": "obra_referencia_enlace_obra_id_obra_referencia_id_fk", + "tableFrom": "obra_referencia_enlace", + "tableTo": "obra_referencia", + "columnsFrom": [ + "obra_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "obra_referencia_enlace_obra_id_plataforma_pk": { + "name": "obra_referencia_enlace_obra_id_plataforma_pk", + "columns": [ + "obra_id", + "plataforma" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.obra_referencia_persona": { + "name": "obra_referencia_persona", + "schema": "", + "columns": { + "obra_id": { + "name": "obra_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "persona_id": { + "name": "persona_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "papel": { + "name": "papel", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "obra_referencia_persona_obra_id_obra_referencia_id_fk": { + "name": "obra_referencia_persona_obra_id_obra_referencia_id_fk", + "tableFrom": "obra_referencia_persona", + "tableTo": "obra_referencia", + "columnsFrom": [ + "obra_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "obra_referencia_persona_persona_id_persona_id_fk": { + "name": "obra_referencia_persona_persona_id_persona_id_fk", + "tableFrom": "obra_referencia_persona", + "tableTo": "persona", + "columnsFrom": [ + "persona_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "obra_referencia_persona_obra_id_persona_id_papel_pk": { + "name": "obra_referencia_persona_obra_id_persona_id_papel_pk", + "columns": [ + "obra_id", + "persona_id", + "papel" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.prompt": { + "name": "prompt", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "modelo_ia_id": { + "name": "modelo_ia_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "genero_id": { + "name": "genero_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "animo_id": { + "name": "animo_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "idioma": { + "name": "idioma", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'en'" + }, + "contenido": { + "name": "contenido", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "notas": { + "name": "notas", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "valoracion": { + "name": "valoracion", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "ejemplo_id": { + "name": "ejemplo_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "preferido": { + "name": "preferido", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "visibilidad": { + "name": "visibilidad", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'privado'" + }, + "estado": { + "name": "estado", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'borrador'" + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "actualizado_en": { + "name": "actualizado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "prompt_genero": { + "name": "prompt_genero", + "columns": [ + { + "expression": "genero_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "prompt_modelo": { + "name": "prompt_modelo", + "columns": [ + { + "expression": "modelo_ia_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "prompt_animo": { + "name": "prompt_animo", + "columns": [ + { + "expression": "animo_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "prompt_modelo_ia_id_modelo_ia_id_fk": { + "name": "prompt_modelo_ia_id_modelo_ia_id_fk", + "tableFrom": "prompt", + "tableTo": "modelo_ia", + "columnsFrom": [ + "modelo_ia_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "prompt_genero_id_genero_id_fk": { + "name": "prompt_genero_id_genero_id_fk", + "tableFrom": "prompt", + "tableTo": "genero", + "columnsFrom": [ + "genero_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "prompt_animo_id_animo_id_fk": { + "name": "prompt_animo_id_animo_id_fk", + "tableFrom": "prompt", + "tableTo": "animo", + "columnsFrom": [ + "animo_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "prompt_ejemplo_id_medio_id_fk": { + "name": "prompt_ejemplo_id_medio_id_fk", + "tableFrom": "prompt", + "tableTo": "medio", + "columnsFrom": [ + "ejemplo_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.termino": { + "name": "termino", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "termino": { + "name": "termino", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "termino_slug_unique": { + "name": "termino_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + }, + "termino_termino_unique": { + "name": "termino_termino_unique", + "nullsNotDistinct": false, + "columns": [ + "termino" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.termino_variante": { + "name": "termino_variante", + "schema": "", + "columns": { + "termino_id": { + "name": "termino_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "forma": { + "name": "forma", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "termino_variante_termino_id_termino_id_fk": { + "name": "termino_variante_termino_id_termino_id_fk", + "tableFrom": "termino_variante", + "tableTo": "termino", + "columnsFrom": [ + "termino_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "termino_variante_termino_id_forma_pk": { + "name": "termino_variante_termino_id_forma_pk", + "columns": [ + "termino_id", + "forma" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.verso": { + "name": "verso", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "genero_id": { + "name": "genero_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "titulo": { + "name": "titulo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "ilustra": { + "name": "ilustra", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "fuente": { + "name": "fuente", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'ejemplo'" + }, + "analisis": { + "name": "analisis", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "medida": { + "name": "medida", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "rima": { + "name": "rima", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "obra_id": { + "name": "obra_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "estado": { + "name": "estado", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'borrador'" + }, + "origen": { + "name": "origen", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'manual'" + }, + "modelo_origen": { + "name": "modelo_origen", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "importado_en": { + "name": "importado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "revisado_por": { + "name": "revisado_por", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "revisado_en": { + "name": "revisado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "verso_genero": { + "name": "verso_genero", + "columns": [ + { + "expression": "genero_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "orden", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "verso_genero_id_genero_id_fk": { + "name": "verso_genero_id_genero_id_fk", + "tableFrom": "verso", + "tableTo": "genero", + "columnsFrom": [ + "genero_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "verso_obra_id_obra_referencia_id_fk": { + "name": "verso_obra_id_obra_referencia_id_fk", + "tableFrom": "verso", + "tableTo": "obra_referencia", + "columnsFrom": [ + "obra_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "verso_cancion_id_cancion_id_fk": { + "name": "verso_cancion_id_cancion_id_fk", + "tableFrom": "verso", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.verso_linea": { + "name": "verso_linea", + "schema": "", + "columns": { + "verso_id": { + "name": "verso_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "numero": { + "name": "numero", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "texto": { + "name": "texto", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "silabas": { + "name": "silabas", + "type": "text[]", + "primaryKey": false, + "notNull": false + }, + "tonicas": { + "name": "tonicas", + "type": "integer[]", + "primaryKey": false, + "notNull": false + }, + "medida": { + "name": "medida", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "rima": { + "name": "rima", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "verso_linea_verso_id_verso_id_fk": { + "name": "verso_linea_verso_id_verso_id_fk", + "tableFrom": "verso_linea", + "tableTo": "verso", + "columnsFrom": [ + "verso_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "verso_linea_verso_id_numero_pk": { + "name": "verso_linea_verso_id_numero_pk", + "columns": [ + "verso_id", + "numero" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.documento_legal": { + "name": "documento_legal", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "titulo": { + "name": "titulo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resumen": { + "name": "resumen", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "orden": { + "name": "orden", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "version_vigente_id": { + "name": "version_vigente_id", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "documento_legal_slug_unique": { + "name": "documento_legal_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.entrada": { + "name": "entrada", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "titulo": { + "name": "titulo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "fecha": { + "name": "fecha", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "resumen": { + "name": "resumen", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "cuerpo": { + "name": "cuerpo", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "imagen_id": { + "name": "imagen_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "estado": { + "name": "estado", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'borrador'" + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "actualizado_en": { + "name": "actualizado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "entrada_fecha": { + "name": "entrada_fecha", + "columns": [ + { + "expression": "fecha", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "entrada_imagen_id_medio_id_fk": { + "name": "entrada_imagen_id_medio_id_fk", + "tableFrom": "entrada", + "tableTo": "medio", + "columnsFrom": [ + "imagen_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "entrada_slug_unique": { + "name": "entrada_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.entrada_cancion": { + "name": "entrada_cancion", + "schema": "", + "columns": { + "entrada_id": { + "name": "entrada_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "entrada_cancion_entrada_id_entrada_id_fk": { + "name": "entrada_cancion_entrada_id_entrada_id_fk", + "tableFrom": "entrada_cancion", + "tableTo": "entrada", + "columnsFrom": [ + "entrada_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "entrada_cancion_cancion_id_cancion_id_fk": { + "name": "entrada_cancion_cancion_id_cancion_id_fk", + "tableFrom": "entrada_cancion", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "entrada_cancion_entrada_id_cancion_id_pk": { + "name": "entrada_cancion_entrada_id_cancion_id_pk", + "columns": [ + "entrada_id", + "cancion_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.entrada_etiqueta": { + "name": "entrada_etiqueta", + "schema": "", + "columns": { + "entrada_id": { + "name": "entrada_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "etiqueta_id": { + "name": "etiqueta_id", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "entrada_etiqueta_entrada_id_entrada_id_fk": { + "name": "entrada_etiqueta_entrada_id_entrada_id_fk", + "tableFrom": "entrada_etiqueta", + "tableTo": "entrada", + "columnsFrom": [ + "entrada_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "entrada_etiqueta_etiqueta_id_etiqueta_id_fk": { + "name": "entrada_etiqueta_etiqueta_id_etiqueta_id_fk", + "tableFrom": "entrada_etiqueta", + "tableTo": "etiqueta", + "columnsFrom": [ + "etiqueta_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "entrada_etiqueta_entrada_id_etiqueta_id_pk": { + "name": "entrada_etiqueta_entrada_id_etiqueta_id_pk", + "columns": [ + "entrada_id", + "etiqueta_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pagina": { + "name": "pagina", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "slug": { + "name": "slug", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "titulo": { + "name": "titulo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "descripcion": { + "name": "descripcion", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "cuerpo": { + "name": "cuerpo", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "estado": { + "name": "estado", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'borrador'" + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "actualizado_en": { + "name": "actualizado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "pagina_slug_unique": { + "name": "pagina_slug_unique", + "nullsNotDistinct": false, + "columns": [ + "slug" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.redireccion": { + "name": "redireccion", + "schema": "", + "columns": { + "desde": { + "name": "desde", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "hacia": { + "name": "hacia", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "permanente": { + "name": "permanente", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "motivo": { + "name": "motivo", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "creada_en": { + "name": "creada_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "redireccion_hacia": { + "name": "redireccion_hacia", + "columns": [ + { + "expression": "hacia", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.version_legal": { + "name": "version_legal", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "documento_id": { + "name": "documento_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cuerpo": { + "name": "cuerpo", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "vigente_desde": { + "name": "vigente_desde", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "resumen_cambios": { + "name": "resumen_cambios", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "version_legal_documento": { + "name": "version_legal_documento", + "columns": [ + { + "expression": "documento_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "vigente_desde", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "version_legal_documento_id_documento_legal_id_fk": { + "name": "version_legal_documento_id_documento_legal_id_fk", + "tableFrom": "version_legal", + "tableTo": "documento_legal", + "columnsFrom": [ + "documento_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.contador_factura": { + "name": "contador_factura", + "schema": "", + "columns": { + "serie": { + "name": "serie", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "ultimo_numero": { + "name": "ultimo_numero", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "actualizado_en": { + "name": "actualizado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.datos_facturacion": { + "name": "datos_facturacion", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "usuario_id": { + "name": "usuario_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tipo": { + "name": "tipo", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'particular'" + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nif": { + "name": "nif", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "direccion": { + "name": "direccion", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "cp": { + "name": "cp", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ciudad": { + "name": "ciudad", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "provincia": { + "name": "provincia", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "pais_codigo": { + "name": "pais_codigo", + "type": "char(2)", + "primaryKey": false, + "notNull": true + }, + "predeterminada": { + "name": "predeterminada", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "actualizado_en": { + "name": "actualizado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "datos_facturacion_usuario": { + "name": "datos_facturacion_usuario", + "columns": [ + { + "expression": "usuario_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "datos_facturacion_usuario_id_usuario_id_fk": { + "name": "datos_facturacion_usuario_id_usuario_id_fk", + "tableFrom": "datos_facturacion", + "tableTo": "usuario", + "columnsFrom": [ + "usuario_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "datos_facturacion_pais_codigo_pais_codigo_fk": { + "name": "datos_facturacion_pais_codigo_pais_codigo_fk", + "tableFrom": "datos_facturacion", + "tableTo": "pais", + "columnsFrom": [ + "pais_codigo" + ], + "columnsTo": [ + "codigo" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.descarga": { + "name": "descarga", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "usuario_id": { + "name": "usuario_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "bajada_en": { + "name": "bajada_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "ip": { + "name": "ip", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "agente": { + "name": "agente", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "descarga_usuario": { + "name": "descarga_usuario", + "columns": [ + { + "expression": "usuario_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "descarga_fecha": { + "name": "descarga_fecha", + "columns": [ + { + "expression": "bajada_en", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "descarga_usuario_id_usuario_id_fk": { + "name": "descarga_usuario_id_usuario_id_fk", + "tableFrom": "descarga", + "tableTo": "usuario", + "columnsFrom": [ + "usuario_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "descarga_cancion_id_cancion_id_fk": { + "name": "descarga_cancion_id_cancion_id_fk", + "tableFrom": "descarga", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.factura": { + "name": "factura", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "pedido_id": { + "name": "pedido_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "serie": { + "name": "serie", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "numero": { + "name": "numero", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "tipo": { + "name": "tipo", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'normal'" + }, + "rectifica_a_id": { + "name": "rectifica_a_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "fecha": { + "name": "fecha", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "base_centimos": { + "name": "base_centimos", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "iva_tipo": { + "name": "iva_tipo", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "iva_cuota_centimos": { + "name": "iva_cuota_centimos", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "total_centimos": { + "name": "total_centimos", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "moneda": { + "name": "moneda", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'eur'" + }, + "datos_congelados": { + "name": "datos_congelados", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "pais_codigo": { + "name": "pais_codigo", + "type": "char(2)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "factura_serie_numero": { + "name": "factura_serie_numero", + "columns": [ + { + "expression": "serie", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "numero", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "factura_pedido": { + "name": "factura_pedido", + "columns": [ + { + "expression": "pedido_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "factura_fecha": { + "name": "factura_fecha", + "columns": [ + { + "expression": "fecha", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "factura_pedido_id_pedido_id_fk": { + "name": "factura_pedido_id_pedido_id_fk", + "tableFrom": "factura", + "tableTo": "pedido", + "columnsFrom": [ + "pedido_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "factura_pais_codigo_pais_codigo_fk": { + "name": "factura_pais_codigo_pais_codigo_fk", + "tableFrom": "factura", + "tableTo": "pais", + "columnsFrom": [ + "pais_codigo" + ], + "columnsTo": [ + "codigo" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.codigo_acceso": { + "name": "codigo_acceso", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "hash": { + "name": "hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expira_en": { + "name": "expira_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "intentos": { + "name": "intentos", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "usado_en": { + "name": "usado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "codigo_acceso_email": { + "name": "codigo_acceso_email", + "columns": [ + { + "expression": "email", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.identidad": { + "name": "identidad", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "proveedor": { + "name": "proveedor", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sujeto": { + "name": "sujeto", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "usuario_id": { + "name": "usuario_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "creada_en": { + "name": "creada_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "ultimo_acceso_en": { + "name": "ultimo_acceso_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "identidad_proveedor_sujeto": { + "name": "identidad_proveedor_sujeto", + "columns": [ + { + "expression": "proveedor", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "sujeto", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "identidad_usuario": { + "name": "identidad_usuario", + "columns": [ + { + "expression": "usuario_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "identidad_usuario_id_usuario_id_fk": { + "name": "identidad_usuario_id_usuario_id_fk", + "tableFrom": "identidad", + "tableTo": "usuario", + "columnsFrom": [ + "usuario_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.limite": { + "name": "limite", + "schema": "", + "columns": { + "clave": { + "name": "clave", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "intentos": { + "name": "intentos", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "expira_en": { + "name": "expira_en", + "type": "bigint", + "primaryKey": false, + "notNull": true + } + }, + "indexes": { + "limite_expira": { + "name": "limite_expira", + "columns": [ + { + "expression": "expira_en", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.sesion": { + "name": "sesion", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "usuario_id": { + "name": "usuario_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expira_en": { + "name": "expira_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "creada_en": { + "name": "creada_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "sesion_usuario": { + "name": "sesion_usuario", + "columns": [ + { + "expression": "usuario_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "sesion_usuario_id_usuario_id_fk": { + "name": "sesion_usuario_id_usuario_id_fk", + "tableFrom": "sesion", + "tableTo": "usuario", + "columnsFrom": [ + "usuario_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.usuario": { + "name": "usuario", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "nombre": { + "name": "nombre", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "ultimo_acceso_en": { + "name": "ultimo_acceso_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "usuario_email_unique": { + "name": "usuario_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.carrito": { + "name": "carrito", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "usuario_id": { + "name": "usuario_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "actualizado_en": { + "name": "actualizado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "carrito_usuario": { + "name": "carrito_usuario", + "columns": [ + { + "expression": "usuario_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "carrito_usuario_id_usuario_id_fk": { + "name": "carrito_usuario_id_usuario_id_fk", + "tableFrom": "carrito", + "tableTo": "usuario", + "columnsFrom": [ + "usuario_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.carrito_item": { + "name": "carrito_item", + "schema": "", + "columns": { + "carrito_id": { + "name": "carrito_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "anadido_en": { + "name": "anadido_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "carrito_item_carrito_id_carrito_id_fk": { + "name": "carrito_item_carrito_id_carrito_id_fk", + "tableFrom": "carrito_item", + "tableTo": "carrito", + "columnsFrom": [ + "carrito_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "carrito_item_cancion_id_cancion_id_fk": { + "name": "carrito_item_cancion_id_cancion_id_fk", + "tableFrom": "carrito_item", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "carrito_item_carrito_id_cancion_id_pk": { + "name": "carrito_item_carrito_id_cancion_id_pk", + "columns": [ + "carrito_id", + "cancion_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.compra": { + "name": "compra", + "schema": "", + "columns": { + "usuario_id": { + "name": "usuario_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pedido_id": { + "name": "pedido_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "comprado_en": { + "name": "comprado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "compra_usuario_id_usuario_id_fk": { + "name": "compra_usuario_id_usuario_id_fk", + "tableFrom": "compra", + "tableTo": "usuario", + "columnsFrom": [ + "usuario_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "compra_cancion_id_cancion_id_fk": { + "name": "compra_cancion_id_cancion_id_fk", + "tableFrom": "compra", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + }, + "compra_pedido_id_pedido_id_fk": { + "name": "compra_pedido_id_pedido_id_fk", + "tableFrom": "compra", + "tableTo": "pedido", + "columnsFrom": [ + "pedido_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "compra_usuario_id_cancion_id_pk": { + "name": "compra_usuario_id_cancion_id_pk", + "columns": [ + "usuario_id", + "cancion_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pedido": { + "name": "pedido", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "usuario_id": { + "name": "usuario_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "sesion_pago_id": { + "name": "sesion_pago_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "estado": { + "name": "estado", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pendiente'" + }, + "packs": { + "name": "packs", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "total_centimos": { + "name": "total_centimos", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "moneda": { + "name": "moneda", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'eur'" + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "pagado_en": { + "name": "pagado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "pedido_usuario": { + "name": "pedido_usuario", + "columns": [ + { + "expression": "usuario_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "pedido_usuario_id_usuario_id_fk": { + "name": "pedido_usuario_id_usuario_id_fk", + "tableFrom": "pedido", + "tableTo": "usuario", + "columnsFrom": [ + "usuario_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "pedido_sesion_pago_id_unique": { + "name": "pedido_sesion_pago_id_unique", + "nullsNotDistinct": false, + "columns": [ + "sesion_pago_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.pedido_item": { + "name": "pedido_item", + "schema": "", + "columns": { + "pedido_id": { + "name": "pedido_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "titulo": { + "name": "titulo", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "pedido_item_pedido_id_pedido_id_fk": { + "name": "pedido_item_pedido_id_pedido_id_fk", + "tableFrom": "pedido_item", + "tableTo": "pedido", + "columnsFrom": [ + "pedido_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "pedido_item_cancion_id_cancion_id_fk": { + "name": "pedido_item_cancion_id_cancion_id_fk", + "tableFrom": "pedido_item", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "pedido_item_pedido_id_cancion_id_pk": { + "name": "pedido_item_pedido_id_cancion_id_pk", + "columns": [ + "pedido_id", + "cancion_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.favorito": { + "name": "favorito", + "schema": "", + "columns": { + "usuario_id": { + "name": "usuario_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "marcado_en": { + "name": "marcado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_favorito_usuario": { + "name": "idx_favorito_usuario", + "columns": [ + { + "expression": "usuario_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "favorito_usuario_id_usuario_id_fk": { + "name": "favorito_usuario_id_usuario_id_fk", + "tableFrom": "favorito", + "tableTo": "usuario", + "columnsFrom": [ + "usuario_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "favorito_cancion_id_cancion_id_fk": { + "name": "favorito_cancion_id_cancion_id_fk", + "tableFrom": "favorito", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "favorito_usuario_id_cancion_id_pk": { + "name": "favorito_usuario_id_cancion_id_pk", + "columns": [ + "usuario_id", + "cancion_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.reproduccion": { + "name": "reproduccion", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "usuario_id": { + "name": "usuario_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "segundos": { + "name": "segundos", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "dia": { + "name": "dia", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "creado_en": { + "name": "creado_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "reproduccion_dia": { + "name": "reproduccion_dia", + "columns": [ + { + "expression": "dia", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "reproduccion_cancion": { + "name": "reproduccion_cancion", + "columns": [ + { + "expression": "cancion_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "reproduccion_usuario": { + "name": "reproduccion_usuario", + "columns": [ + { + "expression": "usuario_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "reproduccion_cancion_id_cancion_id_fk": { + "name": "reproduccion_cancion_id_cancion_id_fk", + "tableFrom": "reproduccion", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "reproduccion_usuario_id_usuario_id_fk": { + "name": "reproduccion_usuario_id_usuario_id_fk", + "tableFrom": "reproduccion", + "tableTo": "usuario", + "columnsFrom": [ + "usuario_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.valoracion": { + "name": "valoracion", + "schema": "", + "columns": { + "usuario_id": { + "name": "usuario_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "cancion_id": { + "name": "cancion_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "puntuacion": { + "name": "puntuacion", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "creada_en": { + "name": "creada_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "actualizada_en": { + "name": "actualizada_en", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "idx_valoracion_cancion": { + "name": "idx_valoracion_cancion", + "columns": [ + { + "expression": "cancion_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "valoracion_usuario_id_usuario_id_fk": { + "name": "valoracion_usuario_id_usuario_id_fk", + "tableFrom": "valoracion", + "tableTo": "usuario", + "columnsFrom": [ + "usuario_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "valoracion_cancion_id_cancion_id_fk": { + "name": "valoracion_cancion_id_cancion_id_fk", + "tableFrom": "valoracion", + "tableTo": "cancion", + "columnsFrom": [ + "cancion_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "valoracion_usuario_id_cancion_id_pk": { + "name": "valoracion_usuario_id_cancion_id_pk", + "columns": [ + "usuario_id", + "cancion_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/drizzle/meta/_journal.json b/drizzle/meta/_journal.json index 226f518..a3fe490 100644 --- a/drizzle/meta/_journal.json +++ b/drizzle/meta/_journal.json @@ -64,6 +64,13 @@ "when": 1788888966189, "tag": "0008_fuera_el_slug_de_las_compras", "breakpoints": true + }, + { + "idx": 9, + "version": "7", + "when": 1788890122515, + "tag": "0009_nota_de_version_y_orden_de_etiquetas", + "breakpoints": true } ] } \ No newline at end of file diff --git a/package.json b/package.json index a4dc018..e1f6cf2 100644 --- a/package.json +++ b/package.json @@ -26,7 +26,9 @@ "db:volcar": "node --experimental-strip-types --import ./scripts/db/resolver-lib.mjs --env-file=.env scripts/db/volcar.mjs", "db:medios": "node --env-file=.env scripts/db/volcar-medios.mjs", "db:generos": "node --env-file=.env scripts/db/sembrar-generos.mjs", - "db:versos": "node --env-file=.env scripts/db/sembrar-versos.mjs" + "db:versos": "node --env-file=.env scripts/db/sembrar-versos.mjs", + "db:completar": "node --env-file=.env scripts/db/completar-catalogo.mjs", + "db:comparar": "node --experimental-strip-types --import ./scripts/db/resolver-lib.mjs --env-file=.env scripts/db/comparar-catalogo.mjs" }, "devDependencies": { "@eslint/js": "^10.0.1", diff --git a/scripts/db/comparar-catalogo.mjs b/scripts/db/comparar-catalogo.mjs new file mode 100644 index 0000000..a70fb8c --- /dev/null +++ b/scripts/db/comparar-catalogo.mjs @@ -0,0 +1,145 @@ +/** + * Compara el catálogo de la base con el de los archivos, campo a campo. + * + * npm run db:comparar + * + * Es la red de la fase 4. Cambiar de dónde salen los datos de veinte rutas sin + * poder comprobar que salen iguales sería confiar en que las pruebas de + * interfaz noten una diferencia de un año o de un porcentaje de autoría, y no + * la notarían: pintan lo que les den. + * + * Lo que se compara es el objeto entero de cada canción, álbum y estilo, con + * las mismas claves y ordenado igual. Las diferencias se listan una a una con + * su ruta —`dorina.registro.reparto[0].porcentaje`— porque un «no coinciden» + * sin más no sirve para arreglar nada. + */ + +import fs from 'node:fs'; +import path from 'node:path'; +import { load as leerYaml } from 'js-yaml'; + +import { parsearAlbum, parsearCancion, parsearEstilo } from '$lib/content/schema'; +import { extraerLineas } from '$lib/content/extracto'; +import { leerCatalogo } from '$lib/server/catalogo'; + +/* + * Los archivos se leen a mano y no por `$lib/content`, que usa + * `import.meta.glob`: eso lo resuelve Vite al construir y en Node no existe. + * Los analizadores sí son los mismos, que es lo que hace que la comparación + * signifique algo. + */ +const RAIZ = 'src/content'; + +const SALTO = String.fromCharCode(10); + +function partir(texto) { + const lineas = texto.split(new RegExp(String.raw`\r?\n`)); + if (lineas[0]?.trim() !== '---') return { datos: {}, cuerpo: texto.trim() }; + const cierre = lineas.indexOf('---', 1); + if (cierre === -1) return { datos: {}, cuerpo: texto.trim() }; + return { + datos: leerYaml(lineas.slice(1, cierre).join(SALTO)) ?? {}, + cuerpo: lineas + .slice(cierre + 1) + .join(SALTO) + .trim() + }; +} + +function leerCarpeta(carpeta, parser) { + const dir = path.join(RAIZ, carpeta); + if (!fs.existsSync(dir)) return []; + return fs + .readdirSync(dir) + .filter((n) => n.endsWith('.md')) + .sort() + .map((nombre) => { + const ruta = path.join(dir, nombre); + const { datos, cuerpo } = partir(fs.readFileSync(ruta, 'utf8')); + const slug = nombre.replace(/\.md$/, ''); + const parseado = parser(datos, slug, ruta); + // El extracto lo inyecta un preprocesador al construir, no el parser. + if (carpeta === 'canciones') parseado.extracto = extraerLineas(cuerpo); + return parseado; + }); +} + +const deArchivo = leerCarpeta('canciones', parsearCancion); +const albumesArchivo = leerCarpeta('albumes', parsearAlbum); +const estilosArchivo = leerCarpeta('estilos', parsearEstilo); + +/** Recorre dos objetos a la vez y devuelve dónde difieren. */ +function diferencias(a, b, ruta = '') { + const fuera = []; + + if (a === b) return fuera; + + if (Array.isArray(a) && Array.isArray(b)) { + if (a.length !== b.length) { + fuera.push(`${ruta}: archivo ${a.length} elementos, base ${b.length}`); + } + for (let i = 0; i < Math.max(a.length, b.length); i++) { + fuera.push(...diferencias(a[i], b[i], `${ruta}[${i}]`)); + } + return fuera; + } + + if (a && b && typeof a === 'object' && typeof b === 'object') { + for (const clave of new Set([...Object.keys(a), ...Object.keys(b)])) { + fuera.push(...diferencias(a[clave], b[clave], ruta ? `${ruta}.${clave}` : clave)); + } + return fuera; + } + + // `undefined` y ausente son lo mismo para este sitio: el tipo los declara + // opcionales y la plantilla los trata igual. + if ((a ?? undefined) === (b ?? undefined)) return fuera; + + fuera.push(`${ruta}: archivo ${JSON.stringify(a)} · base ${JSON.stringify(b)}`); + return fuera; +} + +const base = await leerCatalogo(); + +const grupos = [ + ['canciones', deArchivo, base.canciones], + ['álbumes', albumesArchivo, base.albumes], + ['estilos', estilosArchivo, base.estilos] +]; + +let problemas = 0; + +for (const [nombre, archivo, deBase] of grupos) { + console.log(`\n${nombre.toUpperCase()} · archivo ${archivo.length} · base ${deBase.length}`); + + const porSlug = new Map(deBase.map((x) => [x.slug, x])); + + for (const uno of archivo) { + const otro = porSlug.get(uno.slug); + if (!otro) { + console.log(` ✗ ${uno.slug}: no está en la base`); + problemas++; + continue; + } + porSlug.delete(uno.slug); + + const fuera = diferencias(uno, otro, uno.slug); + if (fuera.length === 0) continue; + + problemas += fuera.length; + console.log(` ✗ ${uno.slug}`); + for (const d of fuera) console.log(` ${d}`); + } + + for (const sobrante of porSlug.keys()) { + console.log(` · ${sobrante}: solo en la base (no es un fallo si se añadió después)`); + } +} + +console.log( + problemas === 0 + ? '\nIdénticos. La base puede sustituir a los archivos sin que cambie nada.' + : `\n${problemas} diferencias. Cada una es algo que la web enseñaría distinto.` +); + +process.exit(problemas === 0 ? 0 : 1); diff --git a/scripts/db/completar-catalogo.mjs b/scripts/db/completar-catalogo.mjs new file mode 100644 index 0000000..490321d --- /dev/null +++ b/scripts/db/completar-catalogo.mjs @@ -0,0 +1,226 @@ +/** + * Ata los cabos que el volcado dejó sueltos. + * + * npm run db:completar + * + * El volcado del catálogo y el de medios se hicieron por separado: el primero + * creó las canciones y el segundo las filas de `medio` con su sha256 y su + * duración, pero **nadie enlazó unas con otras**. Las veintitrés canciones + * tenían `audio_id`, `muestra_id` y `portada_id` a nulo, así que la web habría + * dejado de poder reproducir nada en cuanto leyera de la base. + * + * No se vio al volcar porque el volcado comprobaba las letras carácter a + * carácter —que era lo delicado— y no que las relaciones estuvieran puestas. + * Se vio al comparar el catálogo entero contra los archivos, que es lo que + * hace `npm run db:comparar`. + * + * Rellena, además, lo que no tenía dónde ir hasta la migración 0009: la nota de + * cada versión y el orden en que se escribieron las etiquetas. + * + * Es idempotente: son `UPDATE`. Se puede volver a pasar cuando haga falta. + */ + +import fs from 'node:fs'; +import path from 'node:path'; +import { load as leerYaml } from 'js-yaml'; +import pg from 'pg'; + +const RAIZ = 'src/content'; +const SALTO = String.fromCharCode(10); + +/** Separa el frontmatter del cuerpo, igual que el volcado. */ +function partir(texto) { + const lineas = texto.split(new RegExp(String.raw`\r?\n`)); + if (lineas[0]?.trim() !== '---') return { datos: {}, cuerpo: texto.trim() }; + const cierre = lineas.indexOf('---', 1); + if (cierre === -1) return { datos: {}, cuerpo: texto.trim() }; + return { datos: leerYaml(lineas.slice(1, cierre).join(SALTO)) ?? {}, cuerpo: '' }; +} + +function leerCarpeta(carpeta) { + const dir = path.join(RAIZ, carpeta); + if (!fs.existsSync(dir)) return []; + return fs + .readdirSync(dir) + .filter((n) => n.endsWith('.md')) + .sort() + .map((nombre) => ({ + slug: nombre.replace(new RegExp(String.raw`\.md$`), ''), + datos: partir(fs.readFileSync(path.join(dir, nombre), 'utf8')).datos + })); +} + +const c = new pg.Client({ connectionString: process.env.DATABASE_URL, query_timeout: 60_000 }); +await c.connect(); +await c.query('BEGIN'); + +const contado = { + audio: 0, + muestra: 0, + portadaCancion: 0, + portadaAlbum: 0, + paisAlbum: 0, + nota: 0, + orden: 0 +}; +const avisos = []; + +try { + /* --- Índices de lo que ya hay ----------------------------------------- */ + + const { rows: medios } = await c.query('SELECT id, clave FROM medio'); + const idDeMedio = new Map(medios.map((m) => [m.clave, m.id])); + + const { rows: canciones } = await c.query( + 'SELECT id, slug, version_de_id, version_nombre FROM cancion' + ); + const idDeCancion = new Map(canciones.filter((f) => !f.version_de_id).map((f) => [f.slug, f.id])); + + /* + * Las versiones se buscan por su nombre y no por el slug: el volcado lo + * compuso a partir del nombre —«Versión orquestal» → + * `como-si-nada-version-orquestal`— y rehacer esa cuenta aquí sería tener + * dos formas de calcular lo mismo, que es como acaban discrepando. + */ + const versionesDe = new Map(); + for (const fila of canciones.filter((f) => f.version_de_id)) { + const suyas = versionesDe.get(fila.version_de_id) ?? new Map(); + suyas.set(fila.version_nombre, fila.id); + versionesDe.set(fila.version_de_id, suyas); + } + + const { rows: albumes } = await c.query('SELECT id, slug FROM album'); + const idDeAlbum = new Map(albumes.map((f) => [f.slug, f.id])); + + const { rows: etiquetas } = await c.query('SELECT id, nombre FROM etiqueta'); + const idDeEtiqueta = new Map(etiquetas.map((f) => [f.nombre, f.id])); + + /* + * El país de edición se escribe con su nombre —«España»— y la base guarda + * el código ISO. El volcado se lo saltó y los cuatro discos quedaron sin + * país; la ficha de edición lo enseña. + */ + const { rows: paises } = await c.query('SELECT codigo, nombre FROM pais'); + const codigoDePais = new Map(paises.map((f) => [f.nombre, f.codigo])); + + /** + * La clave de un medio a partir de lo que dice el archivo. + * + * En el frontmatter el audio es una ruta relativa dentro del almacén + * privado; en `medio` la clave lleva delante el almacén, porque el mismo + * nombre existe en dos —`singles/dorina.mp3` está en audio y en muestras— y + * sin el prefijo chocaban. + */ + const enAlmacen = (almacen, ruta) => { + if (!ruta) return null; + // Las portadas se escriben como ruta pública —`/images/…`— y el audio + // como ruta dentro del almacén. La clave lleva el almacén delante, una + // sola vez. + const limpia = ruta.replace(/^\//, '').replace(new RegExp(`^${almacen}/`), ''); + return `${almacen}/${limpia}`; + }; + + /* --- Canciones ---------------------------------------------------------- */ + + for (const { slug, datos } of leerCarpeta('canciones')) { + const cancionId = idDeCancion.get(slug); + if (!cancionId) { + avisos.push(`la canción «${slug}» no está en la base`); + continue; + } + + const audio = idDeMedio.get(enAlmacen('audio', datos.audio)); + const muestra = idDeMedio.get(enAlmacen('muestras', datos.audio)); + const portada = idDeMedio.get(enAlmacen('images', datos.portada)); + + if (datos.audio && !audio) avisos.push(`${slug}: no encuentro el audio ${datos.audio}`); + if (datos.portada && !portada) avisos.push(`${slug}: no encuentro la portada ${datos.portada}`); + + await c.query( + `UPDATE cancion SET audio_id = COALESCE($2, audio_id), + muestra_id = COALESCE($3, muestra_id), portada_id = COALESCE($4, portada_id) + WHERE id = $1`, + [cancionId, audio ?? null, muestra ?? null, portada ?? null] + ); + if (audio) contado.audio++; + if (muestra) contado.muestra++; + if (portada) contado.portadaCancion++; + + /* Las versiones: su audio, su nota y su nombre. */ + for (const version of datos.versiones ?? []) { + const versionId = versionesDe.get(cancionId)?.get(version.nombre); + if (!versionId) { + avisos.push(`${slug}: no encuentro la versión «${version.nombre}»`); + continue; + } + + const audioVersion = idDeMedio.get(enAlmacen('audio', version.audio)); + const muestraVersion = idDeMedio.get(enAlmacen('muestras', version.audio)); + + await c.query( + `UPDATE cancion SET audio_id = COALESCE($2, audio_id), + muestra_id = COALESCE($3, muestra_id), version_nota = $4 WHERE id = $1`, + [versionId, audioVersion ?? null, muestraVersion ?? null, version.nota ?? null] + ); + if (audioVersion) contado.audio++; + if (muestraVersion) contado.muestra++; + if (version.nota) contado.nota++; + } + + /* El orden de las etiquetas, que es el del archivo. */ + for (const [i, nombre] of (datos.etiquetas ?? []).entries()) { + const etiquetaId = idDeEtiqueta.get(nombre); + if (!etiquetaId) { + avisos.push(`${slug}: no conozco la etiqueta «${nombre}»`); + continue; + } + await c.query( + 'UPDATE cancion_etiqueta SET orden = $3 WHERE cancion_id = $1 AND etiqueta_id = $2', + [cancionId, etiquetaId, i] + ); + contado.orden++; + } + } + + /* --- Álbumes ------------------------------------------------------------ */ + + for (const { slug, datos } of leerCarpeta('albumes')) { + const albumId = idDeAlbum.get(slug); + if (!albumId) { + avisos.push(`el álbum «${slug}» no está en la base`); + continue; + } + + const portada = idDeMedio.get(enAlmacen('images', datos.portada)); + if (datos.portada && !portada) { + avisos.push(`${slug}: no encuentro la portada ${datos.portada}`); + } + + const nombrePais = datos.edicion?.pais ?? datos.pais; + const codigoPais = nombrePais ? codigoDePais.get(nombrePais) : null; + if (nombrePais && !codigoPais) avisos.push(`${slug}: no conozco el país «${nombrePais}»`); + + await c.query( + `UPDATE album SET portada_id = COALESCE($2, portada_id), + pais_edicion_codigo = COALESCE($3, pais_edicion_codigo) WHERE id = $1`, + [albumId, portada ?? null, codigoPais ?? null] + ); + if (portada) contado.portadaAlbum++; + if (codigoPais) contado.paisAlbum++; + } + + await c.query('COMMIT'); +} catch (fallo) { + await c.query('ROLLBACK').catch(() => {}); + console.error('Falló, no se ha escrito nada:'); + console.error(' ' + fallo.message); + await c.end(); + process.exit(1); +} + +await c.end(); + +for (const [que, n] of Object.entries(contado)) console.log(` ${que.padEnd(16)} ${n}`); +for (const aviso of avisos) console.log(` aviso: ${aviso}`); +console.log(''); +console.log('Completado. Comprueba con: npm run db:comparar'); diff --git a/scripts/db/env-privado.mjs b/scripts/db/env-privado.mjs new file mode 100644 index 0000000..9002564 --- /dev/null +++ b/scripts/db/env-privado.mjs @@ -0,0 +1,8 @@ +/** + * Lo mínimo de `$env/dynamic/private` para un script. + * + * SvelteKit lo inyecta al compilar; fuera de la aplicación no existe. El + * `--env-file=.env` de Node ya ha llenado `process.env` cuando esto se carga, + * así que basta con exponerlo con el nombre que espera el código del sitio. + */ +export const env = process.env; diff --git a/scripts/db/gancho-lib.mjs b/scripts/db/gancho-lib.mjs index 3ba249f..3468aa7 100644 --- a/scripts/db/gancho-lib.mjs +++ b/scripts/db/gancho-lib.mjs @@ -26,7 +26,8 @@ const RAIZ_LIB = path.resolve('src/lib'); * tipo y el borrado de tipos se lo lleva por delante. */ const SUSTITUTOS = { - '$app/paths': path.resolve('scripts/db/app-paths.mjs') + '$app/paths': path.resolve('scripts/db/app-paths.mjs'), + '$env/dynamic/private': path.resolve('scripts/db/env-privado.mjs') }; /** Prueba el archivo tal cual, con extensión, y como carpeta con índice. */ diff --git a/src/lib/server/catalogo.ts b/src/lib/server/catalogo.ts new file mode 100644 index 0000000..3962587 --- /dev/null +++ b/src/lib/server/catalogo.ts @@ -0,0 +1,371 @@ +/** + * El catálogo, leído de PostgreSQL. + * + * Devuelve **exactamente** los tipos que ya usaba el sitio cuando el catálogo + * vivía en `src/content`: `Cancion`, `Album`, `Estilo`. Es deliberado. Cambiar + * a la vez de dónde salen los datos y qué forma tienen habría dejado veinte + * archivos sin poder comprobar cuál de las dos cosas rompió; así las pruebas + * que ya existen valen de red tal cual. + * + * ## Por qué se carga entero + * + * Son dieciocho temas. Hasta ahora viajaban en el paquete de JavaScript —los + * cargaba `import.meta.glob` al construir—, así que el sitio ya contaba con + * tenerlos todos a mano: el carrito resuelve sus slugs por su cuenta, el + * reproductor arma la cola, las tarjetas miran si el tema está comprado. Leer + * el catálogo entero y guardarlo en memoria mantiene eso funcionando y no pide + * una consulta por tarjeta. + * + * Lo que **no** se carga aquí es la letra completa, que es lo único pesado: de + * ella solo sale el extracto de las tarjetas. La letra entera la pide la ficha + * del tema, y solo la suya. + * + * La caché se tira sola cada minuto. No hay administración todavía; cuando la + * haya, esto tendrá que invalidarse al guardar, no por reloj. + */ + +import { asc, eq } from 'drizzle-orm'; +import { alias } from 'drizzle-orm/pg-core'; +import { db } from './db'; +import { + album, + albumEnlace, + autoria, + cancion, + cancionEnlace, + cancionEtiqueta, + cancionPersona, + creditoAlbum, + estilo, + etiqueta, + medio, + pais, + persona, + registroObra, + traduccion, + video +} from './db/schema'; +import { extraerLineas } from '$lib/content/extracto'; +import type { + Album, + Cancion, + Enlaces, + Estilo, + FormatoDeEdicion, + Plataforma, + RegistroDeObra, + VersionMusical, + VideoDeCancion +} from '$lib/types'; + +export interface Catalogo { + estilos: Estilo[]; + albumes: Album[]; + canciones: Cancion[]; +} + +const VIDA_MS = 60_000; + +let guardado: { catalogo: Catalogo; hasta: number } | null = null; + +/** Tira la caché. La llamará la administración el día que exista. */ +export function olvidarCatalogo(): void { + guardado = null; +} + +export async function leerCatalogo(): Promise { + if (guardado && Date.now() < guardado.hasta) return guardado.catalogo; + + const catalogo = await cargar(); + guardado = { catalogo, hasta: Date.now() + VIDA_MS }; + return catalogo; +} + +/** Agrupa filas por una clave, que es lo que se hace ocho veces aquí abajo. */ +function porClave(filas: T[], clave: (f: T) => K): Map { + const mapa = new Map(); + for (const fila of filas) { + const k = clave(fila); + const lista = mapa.get(k); + if (lista) lista.push(fila); + else mapa.set(k, [fila]); + } + return mapa; +} + +/** Los enlaces llegan como filas y el sitio los espera como objeto. */ +function comoEnlaces(filas: { plataforma: string; url: string }[]): Enlaces { + const enlaces: Enlaces = {}; + for (const f of filas) enlaces[f.plataforma as Plataforma] = f.url; + return enlaces; +} + +/** + * De clave de almacén a ruta pública. + * + * Las imágenes se sirven de `/static`, así que su clave —`images/…`— es ya la + * ruta con una barra delante. El audio no: ese vive en un almacén privado y no + * tiene URL pública, por eso no pasa por aquí. + */ +function rutaPublica(clave: string | null): string | undefined { + return clave ? `/${clave}` : undefined; +} + +async function cargar(): Promise { + /* + * Alias de verdad y no la misma tabla dos veces: una canción se une a + * `medio` por su audio y otra vez por su portada, y sin alias Postgres ve + * un solo `medio` y devuelve la misma fila para los dos. + */ + const audio = alias(medio, 'audio'); + const portadaCancion = alias(medio, 'portada_cancion'); + const portadaAlbum = alias(medio, 'portada_album'); + + const [ + filasEstilo, + filasAlbum, + filasCancion, + personas, + etiquetas, + enlacesCancion, + enlacesAlbum, + videos, + traducciones, + registros, + partes, + creditos + ] = await Promise.all([ + db.select().from(estilo).orderBy(asc(estilo.orden), asc(estilo.nombre)), + + db + .select({ + fila: album, + portadaClave: portadaAlbum.clave, + paisNombre: pais.nombre + }) + .from(album) + .leftJoin(portadaAlbum, eq(portadaAlbum.id, album.portadaId)) + // El archivo decía «España» y la base guarda «ES»: el nombre sale de + // la tabla de países, que es donde vive una sola vez. + .leftJoin(pais, eq(pais.codigo, album.paisEdicionCodigo)) + .orderBy(asc(album.fecha)), + + db + .select({ + fila: cancion, + estiloSlug: estilo.slug, + albumSlug: album.slug, + audioClave: audio.clave, + audioDuracion: audio.duracionS, + portadaClave: portadaCancion.clave + }) + .from(cancion) + .innerJoin(estilo, eq(estilo.id, cancion.estiloId)) + .leftJoin(album, eq(album.id, cancion.albumId)) + .leftJoin(audio, eq(audio.id, cancion.audioId)) + .leftJoin(portadaCancion, eq(portadaCancion.id, cancion.portadaId)) + .orderBy(asc(cancion.numero), asc(cancion.titulo)), + + db + .select({ + cancionId: cancionPersona.cancionId, + rol: cancionPersona.rol, + nombre: persona.nombre, + orden: cancionPersona.orden + }) + .from(cancionPersona) + .innerJoin(persona, eq(persona.id, cancionPersona.personaId)) + .orderBy(asc(cancionPersona.orden)), + + db + .select({ cancionId: cancionEtiqueta.cancionId, nombre: etiqueta.nombre }) + .from(cancionEtiqueta) + .innerJoin(etiqueta, eq(etiqueta.id, cancionEtiqueta.etiquetaId)) + // Por `orden` y no alfabéticamente: la primera etiqueta de un tema + // dice de qué va, y las de después matizan. + .orderBy(asc(cancionEtiqueta.orden)), + + db + .select({ + cancionId: cancionEnlace.cancionId, + plataforma: cancionEnlace.plataforma, + url: cancionEnlace.url + }) + .from(cancionEnlace), + + db + .select({ + albumId: albumEnlace.albumId, + plataforma: albumEnlace.plataforma, + url: albumEnlace.url + }) + .from(albumEnlace), + + db + .select({ cancionId: video.cancionId, youtube: video.youtubeId, titulo: video.titulo }) + .from(video) + .orderBy(asc(video.orden)), + + db + .select({ cancionId: traduccion.cancionId, texto: traduccion.texto }) + .from(traduccion) + .where(eq(traduccion.idioma, 'es')), + + db.select().from(registroObra), + + db + .select({ + cancionId: autoria.cancionId, + rol: autoria.rol, + porcentaje: autoria.porcentaje, + nombre: persona.nombre + }) + .from(autoria) + .innerJoin(persona, eq(persona.id, autoria.personaId)), + + db + .select({ + albumId: creditoAlbum.albumId, + rol: creditoAlbum.rol, + nombre: creditoAlbum.nombre, + personaNombre: persona.nombre + }) + .from(creditoAlbum) + .leftJoin(persona, eq(persona.id, creditoAlbum.personaId)) + .orderBy(asc(creditoAlbum.orden)) + ]); + + /* --- Índices para no recorrer listas dentro de bucles ------------------ */ + + const porCancion = { + personas: porClave(personas, (p) => p.cancionId), + etiquetas: porClave(etiquetas, (e) => e.cancionId), + enlaces: porClave(enlacesCancion, (e) => e.cancionId), + videos: porClave(videos, (v) => v.cancionId), + partes: porClave(partes, (p) => p.cancionId) + }; + const traduccionDe = new Map(traducciones.map((t) => [t.cancionId, t.texto])); + const registroDe = new Map(registros.map((r) => [r.cancionId, r])); + const enlacesDeAlbum = porClave(enlacesAlbum, (e) => e.albumId); + const creditosDeAlbum = porClave(creditos, (c) => c.albumId); + + /* --- Estilos ----------------------------------------------------------- */ + + const estilos: Estilo[] = filasEstilo.map((e) => ({ + slug: e.slug, + nombre: e.nombre, + resumen: e.resumen, + orden: e.orden, + principal: e.principal, + imagen: undefined + })); + + /* --- Álbumes ----------------------------------------------------------- */ + + const slugDeEstilo = new Map(filasEstilo.map((e) => [e.id, e.slug])); + + const albumes: Album[] = filasAlbum.map(({ fila, portadaClave, paisNombre }) => ({ + slug: fila.slug, + titulo: fila.titulo, + estilo: slugDeEstilo.get(fila.estiloId) ?? '', + fecha: fila.fecha, + tipo: fila.tipo, + portada: rutaPublica(portadaClave) ?? '', + sello: fila.sello ?? undefined, + resumen: fila.resumen, + destacado: fila.destacado, + enlaces: comoEnlaces(enlacesDeAlbum.get(fila.id) ?? []), + // El álbum sintético de singles no existe en la base: lo compone quien + // lo necesita, igual que antes lo componía el módulo de contenido. + sintetico: false, + edicion: { + numeroCatalogo: fila.numeroCatalogo ?? undefined, + formatos: (fila.formatos ?? []) as FormatoDeEdicion[], + pais: paisNombre ?? undefined, + creditos: (creditosDeAlbum.get(fila.id) ?? []).map((c) => ({ + rol: c.rol, + nombre: c.personaNombre ?? c.nombre ?? '' + })) + } + })); + + /* --- Canciones ---------------------------------------------------------- */ + + /* + * Las versiones son filas de `cancion` con `version_de_id`, no una tabla + * aparte: se decidió así porque una versión puede cambiar de estilo, de + * etiquetas y de todo lo demás. Aquí se separan las principales de sus + * versiones y cada una vuelve con las suyas colgando. + */ + const versionesDe = porClave( + filasCancion.filter((f) => f.fila.versionDeId !== null), + (f) => f.fila.versionDeId! + ); + + const canciones: Cancion[] = filasCancion + .filter((f) => f.fila.versionDeId === null) + .map(({ fila, estiloSlug, albumSlug, audioClave, audioDuracion, portadaClave }) => { + const suyas = porCancion.personas.get(fila.id) ?? []; + const registro = registroDe.get(fila.id); + const misPartes = porCancion.partes.get(fila.id) ?? []; + + const versiones: VersionMusical[] = (versionesDe.get(fila.id) ?? []) + .sort((a, b) => a.fila.versionOrden - b.fila.versionOrden) + .map((v) => ({ + id: v.fila.slug.replace(`${fila.slug}-`, ''), + nombre: v.fila.versionNombre ?? '', + audio: v.audioClave?.replace(/^audio\//, '') ?? '', + duracion: v.fila.duracionS ?? v.audioDuracion ?? undefined, + nota: v.fila.versionNota ?? undefined + })); + + const registroDeObra: RegistroDeObra = { + iswc: registro?.iswc ?? undefined, + isrc: registro?.isrc ?? undefined, + entidad: registro?.entidad ?? undefined, + numero: registro?.numero ?? undefined, + editorial: registro?.editorial ?? undefined, + reparto: misPartes.map((p) => ({ + nombre: p.nombre, + rol: p.rol, + porcentaje: Number(p.porcentaje) + })) + }; + + const videosDe: VideoDeCancion[] = (porCancion.videos.get(fila.id) ?? []).map((v) => ({ + youtube: v.youtube, + titulo: v.titulo + })); + + return { + slug: fila.slug, + titulo: fila.titulo, + estilo: estiloSlug, + album: albumSlug ?? null, + numero: fila.numero, + audio: audioClave?.replace(/^audio\//, ''), + duracion: fila.duracionS ?? audioDuracion ?? undefined, + ano: fila.ano ?? undefined, + letra: suyas.filter((p) => p.rol === 'letra').map((p) => p.nombre), + musica: suyas.filter((p) => p.rol === 'musica').map((p) => p.nombre), + interpretes: suyas.filter((p) => p.rol === 'interprete').map((p) => p.nombre), + destacada: fila.destacada, + etiquetas: (porCancion.etiquetas.get(fila.id) ?? []).map((e) => e.nombre), + enlaces: comoEnlaces(porCancion.enlaces.get(fila.id) ?? []), + instrumental: fila.instrumental, + idioma: fila.idioma, + traduccion: traduccionDe.get(fila.id) ?? undefined, + portada: rutaPublica(portadaClave), + inspiracion: fila.inspiracion ? fila.inspiracion.split('\n\n').filter(Boolean) : [], + // El mismo extracto que inyectaba el preprocesador, con la misma + // función: son los primeros versos, no un resumen. + extracto: extraerLineas(fila.letra ?? ''), + versiones, + videos: videosDe, + alaVenta: fila.alaVenta, + registro: registroDeObra + } satisfies Cancion; + }); + + return { estilos, albumes, canciones }; +} diff --git a/src/lib/server/db/schema/catalogo.ts b/src/lib/server/db/schema/catalogo.ts index 979aa0d..fcd0ccf 100644 --- a/src/lib/server/db/schema/catalogo.ts +++ b/src/lib/server/db/schema/catalogo.ts @@ -136,6 +136,8 @@ export const cancion = pgTable( versionDeId: text('version_de_id'), /** Nombre del arreglo: «Versión orquestal», «Maqueta 2018». */ versionNombre: text('version_nombre'), + /** Qué tiene de particular ese arreglo. Va en la ficha, junto al nombre. */ + versionNota: text('version_nota'), /** Orden entre las versiones de un mismo tema. */ versionOrden: integer('version_orden').notNull().default(0), @@ -354,7 +356,13 @@ export const cancionEtiqueta = pgTable( .references(() => cancion.id, { onDelete: 'cascade' }), etiquetaId: text('etiqueta_id') .notNull() - .references(() => etiqueta.id, { onDelete: 'cascade' }) + .references(() => etiqueta.id, { onDelete: 'cascade' }), + /* + * El orden en que se escribieron, que no es el alfabético y no es + * casual: la primera etiqueta de un tema es de lo que va, y las de + * después matizan. Sin esta columna, la ficha las reordenaba sola. + */ + orden: integer('orden').notNull().default(0) }, (t) => [primaryKey({ columns: [t.cancionId, t.etiquetaId] })] );