-- Table: sonex.app_logs

-- DROP TABLE IF EXISTS sonex.app_logs;

CREATE TABLE IF NOT EXISTS sonex.app_logs
(
    error_id character varying(12) COLLATE pg_catalog."default" NOT NULL,
    occurred_at timestamp(3) without time zone NOT NULL,
    level character varying(32) COLLATE pg_catalog."default" NOT NULL,
    application_name text COLLATE pg_catalog."default" NOT NULL,
    app_version text COLLATE pg_catalog."default" NOT NULL,
    instance_id text COLLATE pg_catalog."default" NOT NULL,
    user_name text COLLATE pg_catalog."default" NOT NULL,
    machine_name text COLLATE pg_catalog."default" NOT NULL,
    os_version text COLLATE pg_catalog."default" NOT NULL,
    current_page_title text COLLATE pg_catalog."default",
    current_page text COLLATE pg_catalog."default",
    source text COLLATE pg_catalog."default" NOT NULL,
    operation text COLLATE pg_catalog."default" NOT NULL,
    is_unhandled boolean NOT NULL DEFAULT false,
    message text COLLATE pg_catalog."default" NOT NULL,
    reported_message text COLLATE pg_catalog."default",
    exception_type text COLLATE pg_catalog."default",
    exception_text text COLLATE pg_catalog."default",
    context text COLLATE pg_catalog."default",
    exception_data text COLLATE pg_catalog."default",
    CONSTRAINT pk_app_logs PRIMARY KEY (error_id)
)

TABLESPACE pg_default;

ALTER TABLE IF EXISTS sonex.app_logs
    OWNER to postgres;

REVOKE ALL ON TABLE sonex.app_logs FROM sonex;

GRANT ALL ON TABLE sonex.app_logs TO postgres;

GRANT INSERT, DELETE, SELECT, UPDATE ON TABLE sonex.app_logs TO sonex;
-- Index: ix_app_logs_application_name

-- DROP INDEX IF EXISTS sonex.ix_app_logs_application_name;

CREATE INDEX IF NOT EXISTS ix_app_logs_application_name
    ON sonex.app_logs USING btree
    (application_name COLLATE pg_catalog."default" ASC NULLS LAST)
    TABLESPACE pg_default;
-- Index: ix_app_logs_instance_id

-- DROP INDEX IF EXISTS sonex.ix_app_logs_instance_id;

CREATE INDEX IF NOT EXISTS ix_app_logs_instance_id
    ON sonex.app_logs USING btree
    (instance_id COLLATE pg_catalog."default" ASC NULLS LAST)
    TABLESPACE pg_default;
-- Index: ix_app_logs_level

-- DROP INDEX IF EXISTS sonex.ix_app_logs_level;

CREATE INDEX IF NOT EXISTS ix_app_logs_level
    ON sonex.app_logs USING btree
    (level COLLATE pg_catalog."default" ASC NULLS LAST)
    TABLESPACE pg_default;
-- Index: ix_app_logs_occurred_at

-- DROP INDEX IF EXISTS sonex.ix_app_logs_occurred_at;

CREATE INDEX IF NOT EXISTS ix_app_logs_occurred_at
    ON sonex.app_logs USING btree
    (occurred_at DESC NULLS FIRST)
    TABLESPACE pg_default;