-- Active: 1731588378271@@vm.baseware.net@9432@metamodule@public

-- drop public.station

DROP TABLE IF EXISTS public.station;
DROP SEQUENCE IF EXISTS public.station_id_seq;

-- drop public.zone

DROP TABLE IF EXISTS public.zone;
DROP SEQUENCE IF EXISTS public.zone_id_seq;

-- drop public.grid

DROP TABLE IF EXISTS public.grid;
DROP SEQUENCE IF EXISTS public.grid_id_seq;

-- public.grid

CREATE SEQUENCE IF NOT EXISTS public.grid_id_seq;

ALTER SEQUENCE public.grid_id_seq
    OWNER TO postgres;
	
CREATE TABLE IF NOT EXISTS public.grid
(
    id integer NOT NULL DEFAULT nextval('grid_id_seq'::regclass),
    name character varying(64) COLLATE pg_catalog."default" NOT NULL,
    description character varying(512) COLLATE pg_catalog."default",
    op integer NOT NULL DEFAULT '-1'::integer,
    ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT grid_id_PrimaryKey PRIMARY KEY (id)
)
TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.grid
    OWNER to postgres;

-- public.zone

CREATE SEQUENCE IF NOT EXISTS public.zone_id_seq;

ALTER SEQUENCE public.zone_id_seq
    OWNER TO postgres;

CREATE TABLE IF NOT EXISTS public.zone
(
    id integer NOT NULL DEFAULT nextval('zone_id_seq'::regclass),
	grid_id integer,
    name character varying(64) COLLATE pg_catalog."default" NOT NULL,
    description character varying(512) COLLATE pg_catalog."default",
    op integer NOT NULL DEFAULT '-1'::integer,
    ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT zone_id_PrimaryKey PRIMARY KEY (id),
    CONSTRAINT zone_ForeignKey_grid_id FOREIGN KEY ("grid_id")
        REFERENCES public.grid (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        NOT VALID
)
TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.zone
    OWNER to postgres;


-- public.station

CREATE SEQUENCE IF NOT EXISTS public.station_id_seq;

ALTER SEQUENCE public.station_id_seq
    OWNER TO postgres;

CREATE TABLE IF NOT EXISTS public.station
(
    id integer NOT NULL DEFAULT nextval('station_id_seq'::regclass),
	zone_id integer,
    name character varying(64) COLLATE pg_catalog."default" NOT NULL,
    description character varying(512) COLLATE pg_catalog."default",
	is_local boolean DEFAULT false,
    op integer NOT NULL DEFAULT '-1'::integer,
    ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
    CONSTRAINT station_id_PrimaryKey PRIMARY KEY (id),
    CONSTRAINT station_ForeignKey_zone_id FOREIGN KEY (zone_id)
        REFERENCES public.zone (id) MATCH SIMPLE
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
        NOT VALID
)
TABLESPACE pg_default;

ALTER TABLE IF EXISTS public.station
    OWNER to postgres;

