-- Ejemplos de versos, y enlaces a dónde escuchar las obras. -- -- Lo primero es lo que faltaba para que la ficha enseñe y no solo describa: se -- podía leer que el bolero va en octosílabo y endecasílabo alternados sin ver -- nunca uno. La unidad es la estrofa, porque la rima y la alternancia de -- medidas no se ven en un verso suelto, y cada verso lleva su escansión. -- -- Lo segundo sustituye la columna `enlace` de `obra_referencia`, que era texto -- suelto y solo daba sitio para uno. Una obra está en Spotify **y** en YouTube. -- La columna estaba vacía en las diecisiete filas, así que no hay nada que -- trasladar. CREATE TABLE "obra_referencia_enlace" ( "obra_id" text NOT NULL, "plataforma" text NOT NULL, "url" text NOT NULL, CONSTRAINT "obra_referencia_enlace_obra_id_plataforma_pk" PRIMARY KEY("obra_id","plataforma") ); --> statement-breakpoint CREATE TABLE "verso" ( "id" text PRIMARY KEY NOT NULL, "genero_id" text NOT NULL, "titulo" text NOT NULL, "ilustra" text NOT NULL, "fuente" text DEFAULT 'ejemplo' NOT NULL, "analisis" text, "medida" text, "rima" text, "obra_id" text, "cancion_id" text, "orden" integer DEFAULT 0 NOT NULL, "estado" text DEFAULT 'borrador' NOT NULL, "origen" text DEFAULT 'manual' NOT NULL, "modelo_origen" text, "importado_en" timestamp with time zone, "revisado_por" text, "revisado_en" timestamp with time zone ); --> statement-breakpoint CREATE TABLE "verso_linea" ( "verso_id" text NOT NULL, "numero" integer NOT NULL, "texto" text NOT NULL, "silabas" text[], "tonicas" integer[], "medida" integer, "rima" text, CONSTRAINT "verso_linea_verso_id_numero_pk" PRIMARY KEY("verso_id","numero") ); --> statement-breakpoint ALTER TABLE "obra_referencia_enlace" ADD CONSTRAINT "obra_referencia_enlace_obra_id_obra_referencia_id_fk" FOREIGN KEY ("obra_id") REFERENCES "public"."obra_referencia"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "verso" ADD CONSTRAINT "verso_genero_id_genero_id_fk" FOREIGN KEY ("genero_id") REFERENCES "public"."genero"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint ALTER TABLE "verso" ADD CONSTRAINT "verso_obra_id_obra_referencia_id_fk" FOREIGN KEY ("obra_id") REFERENCES "public"."obra_referencia"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint ALTER TABLE "verso" ADD CONSTRAINT "verso_cancion_id_cancion_id_fk" FOREIGN KEY ("cancion_id") REFERENCES "public"."cancion"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint ALTER TABLE "verso_linea" ADD CONSTRAINT "verso_linea_verso_id_verso_id_fk" FOREIGN KEY ("verso_id") REFERENCES "public"."verso"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint CREATE INDEX "verso_genero" ON "verso" USING btree ("genero_id","orden");--> statement-breakpoint ALTER TABLE "obra_referencia" DROP COLUMN "enlace"; --> statement-breakpoint -- Un fragmento de obra ajena sin decir de quién es no se puede publicar, y un -- verso «propio» sin canción detrás es una afirmación sin respaldo. Que lo -- impida la tabla y no el cuidado de quien carga los datos. ALTER TABLE "verso" ADD CONSTRAINT "verso_cita_acredita" CHECK ("fuente" <> 'cita' OR "obra_id" IS NOT NULL); --> statement-breakpoint ALTER TABLE "verso" ADD CONSTRAINT "verso_propio_apunta" CHECK ("fuente" <> 'propio' OR "cancion_id" IS NOT NULL); --> statement-breakpoint -- Un alejandrino son catorce sílabas y es de los largos. Veinte es un error de -- carga, no un verso. ALTER TABLE "verso_linea" ADD CONSTRAINT "verso_linea_medida_creible" CHECK ("medida" IS NULL OR "medida" BETWEEN 1 AND 20);