-- +goose Up
-- Diff code generated with pgModeler (PostgreSQL Database Modeler)
-- pgModeler version: 1.2.0-alpha1
-- Diff date: 2025-04-15 00:18:26
-- Source model: dev1
-- Database: dev1
-- PostgreSQL version: 17.0

-- [ Diff summary ]
-- Dropped objects: 0
-- Created objects: 6
-- Changed objects: 0

SET search_path=public,pg_catalog;
-- ddl-end --


-- [ Created objects ] --
-- object: width | type: COLUMN --
ALTER TABLE public.file ADD COLUMN width smallint;
-- ddl-end --


-- object: height | type: COLUMN --
ALTER TABLE public.file ADD COLUMN height smallint;
-- ddl-end --


-- object: public.box | type: TABLE --
-- DROP TABLE IF EXISTS public.box CASCADE;
CREATE TABLE public.box (
	id uuid NOT NULL,
	url varchar(256) NOT NULL,
	edit_code varchar(64) NOT NULL,
	header varchar(4096),
	private boolean NOT NULL DEFAULT false,
	moderation boolean NOT NULL DEFAULT false,
	created_at timestamp NOT NULL DEFAULT current_timestamp,
	last_updated_at timestamp NOT NULL DEFAULT current_timestamp,
	CONSTRAINT url_uq UNIQUE (url),
	CONSTRAINT box_pk PRIMARY KEY (id)
);
-- ddl-end --
ALTER TABLE public.box OWNER TO dev;
-- ddl-end --

-- object: id_box | type: COLUMN --
ALTER TABLE public.file ADD COLUMN id_box uuid;
-- ddl-end --
INSERT INTO public.box (id, url, edit_code) VALUES ('ce407978-b599-4cd6-9ddf-e9249280d321', '1', 'foobar');
UPDATE public.file SET id_box = 'ce407978-b599-4cd6-9ddf-e9249280d321';
ALTER TABLE public.file ALTER COLUMN id_box SET NOT NULL;


-- object: md5 | type: COLUMN --
ALTER TABLE public.file ADD COLUMN md5 text;
-- ddl-end --
UPDATE public.file SET md5 = '';
ALTER TABLE public.file ALTER COLUMN md5 SET NOT NULL;




-- [ Created foreign keys ] --
-- object: box_fk | type: CONSTRAINT --
-- ALTER TABLE public.file DROP CONSTRAINT IF EXISTS box_fk CASCADE;
ALTER TABLE public.file ADD CONSTRAINT box_fk FOREIGN KEY (id_box)
REFERENCES public.box (id) MATCH FULL
ON DELETE RESTRICT ON UPDATE CASCADE;
-- ddl-end --

