diff --git a/config/config.exs b/config/config.exs index 4b9fef76..e898c3e6 100644 --- a/config/config.exs +++ b/config/config.exs @@ -59,8 +59,6 @@ config :philomena, PhilomenaWeb.Endpoint, secret_key_base: "xZYTon09JNRrj8snd7KL31wya4x71jmo5aaSSRmw1dGjWLRmEwWMTccwxgsGFGjM", render_errors: [view: PhilomenaWeb.ErrorView, accepts: ~w(html json)] -config :philomena, :generators, migration: false - config :phoenix, :template_engines, slim: PhoenixSlime.Engine, slime: PhoenixSlime.Engine, diff --git a/lib/philomena/images/source.ex b/lib/philomena/images/source.ex new file mode 100644 index 00000000..1b3609f4 --- /dev/null +++ b/lib/philomena/images/source.ex @@ -0,0 +1,15 @@ +defmodule Philomena.Images.Source do + use Ecto.Schema + import Ecto.Changeset + + schema "image_sources" do + timestamps() + end + + @doc false + def changeset(source, attrs) do + source + |> cast(attrs, []) + |> validate_required([]) + end +end diff --git a/priv/repo/migrations/20200503002523_create_image_sources.exs b/priv/repo/migrations/20200503002523_create_image_sources.exs new file mode 100644 index 00000000..ba22b566 --- /dev/null +++ b/priv/repo/migrations/20200503002523_create_image_sources.exs @@ -0,0 +1,16 @@ +defmodule Philomena.Repo.Migrations.CreateImageSources do + use Ecto.Migration + + def change do + create table(:image_sources) do + add :image_id, references(:images), null: false + add :source, :text, null: false + end + + create unique_index("image_sources", [:image_id, :source]) + + create constraint("image_sources", "length_must_be_valid", + check: "length(source) between 8 and 1024" + ) + end +end diff --git a/priv/repo/structure.sql b/priv/repo/structure.sql index 988c30f4..134c4952 100644 --- a/priv/repo/structure.sql +++ b/priv/repo/structure.sql @@ -788,6 +788,37 @@ CREATE SEQUENCE public.image_intensities_id_seq ALTER SEQUENCE public.image_intensities_id_seq OWNED BY public.image_intensities.id; +-- +-- Name: image_sources; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.image_sources ( + id bigint NOT NULL, + image_id bigint NOT NULL, + source text NOT NULL, + CONSTRAINT length_must_be_valid CHECK (((length(source) >= 8) AND (length(source) <= 1024))) +); + + +-- +-- Name: image_sources_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.image_sources_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: image_sources_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.image_sources_id_seq OWNED BY public.image_sources.id; + + -- -- Name: image_subscriptions; Type: TABLE; Schema: public; Owner: - -- @@ -1237,6 +1268,16 @@ CREATE SEQUENCE public.roles_id_seq ALTER SEQUENCE public.roles_id_seq OWNED BY public.roles.id; +-- +-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.schema_migrations ( + version bigint NOT NULL, + inserted_at timestamp(0) without time zone +); + + -- -- Name: site_notices; Type: TABLE; Schema: public; Owner: - -- @@ -2139,6 +2180,13 @@ ALTER TABLE ONLY public.image_features ALTER COLUMN id SET DEFAULT nextval('publ ALTER TABLE ONLY public.image_intensities ALTER COLUMN id SET DEFAULT nextval('public.image_intensities_id_seq'::regclass); +-- +-- Name: image_sources id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.image_sources ALTER COLUMN id SET DEFAULT nextval('public.image_sources_id_seq'::regclass); + + -- -- Name: images id; Type: DEFAULT; Schema: public; Owner: - -- @@ -2487,6 +2535,14 @@ ALTER TABLE ONLY public.image_intensities ADD CONSTRAINT image_intensities_pkey PRIMARY KEY (id); +-- +-- Name: image_sources image_sources_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.image_sources + ADD CONSTRAINT image_sources_pkey PRIMARY KEY (id); + + -- -- Name: images images_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -2567,6 +2623,14 @@ ALTER TABLE ONLY public.roles ADD CONSTRAINT roles_pkey PRIMARY KEY (id); +-- +-- Name: schema_migrations schema_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.schema_migrations + ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version); + + -- -- Name: site_notices site_notices_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- @@ -2718,6 +2782,13 @@ ALTER TABLE ONLY public.versions CREATE INDEX image_intensities_index ON public.image_intensities USING btree (nw, ne, sw, se); +-- +-- Name: image_sources_image_id_source_index; Type: INDEX; Schema: public; Owner: - +-- + +CREATE UNIQUE INDEX image_sources_image_id_source_index ON public.image_sources USING btree (image_id, source); + + -- -- Name: index_adverts_on_live; Type: INDEX; Schema: public; Owner: - -- @@ -4630,7 +4701,17 @@ ALTER TABLE ONLY public.gallery_subscriptions ADD CONSTRAINT fk_rails_fa77f3cebe FOREIGN KEY (gallery_id) REFERENCES public.galleries(id) ON UPDATE CASCADE ON DELETE CASCADE; +-- +-- Name: image_sources image_sources_image_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.image_sources + ADD CONSTRAINT image_sources_image_id_fkey FOREIGN KEY (image_id) REFERENCES public.images(id); + + -- -- PostgreSQL database dump complete -- +INSERT INTO public."schema_migrations" (version) VALUES (20200503002523); +