Simplify migration SQL.

Update fresh.

Fixes #17
This commit is contained in:
Bruno Bernardino
2024-11-21 14:03:08 +00:00
parent 560ea569a0
commit e0b8ea6e30
4 changed files with 28 additions and 227 deletions

View File

@@ -9,27 +9,6 @@ SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: bewcloud_user_sessions; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.bewcloud_user_sessions (
id uuid DEFAULT gen_random_uuid(),
user_id uuid DEFAULT gen_random_uuid(),
expires_at timestamp with time zone NOT NULL,
last_seen_at timestamp with time zone DEFAULT now(),
created_at timestamp with time zone DEFAULT now()
);
ALTER TABLE public.bewcloud_user_sessions OWNER TO postgres;
--
-- Name: bewcloud_users; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.bewcloud_users (
id uuid DEFAULT gen_random_uuid(),
email character varying NOT NULL,
@@ -40,12 +19,20 @@ CREATE TABLE public.bewcloud_users (
created_at timestamp with time zone DEFAULT now()
);
ALTER TABLE ONLY public.bewcloud_users ADD CONSTRAINT bewcloud_users_pkey PRIMARY KEY (id);
ALTER TABLE public.bewcloud_users OWNER TO postgres;
--
-- Name: bewcloud_verification_codes; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.bewcloud_user_sessions (
id uuid DEFAULT gen_random_uuid(),
user_id uuid DEFAULT gen_random_uuid(),
expires_at timestamp with time zone NOT NULL,
last_seen_at timestamp with time zone DEFAULT now(),
created_at timestamp with time zone DEFAULT now()
);
ALTER TABLE ONLY public.bewcloud_user_sessions ADD CONSTRAINT bewcloud_user_sessions_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.bewcloud_user_sessions ADD CONSTRAINT bewcloud_user_sessions_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.bewcloud_users(id);
CREATE TABLE public.bewcloud_verification_codes (
id uuid DEFAULT gen_random_uuid(),
@@ -56,13 +43,9 @@ CREATE TABLE public.bewcloud_verification_codes (
created_at timestamp with time zone DEFAULT now()
);
ALTER TABLE ONLY public.bewcloud_verification_codes ADD CONSTRAINT bewcloud_verification_codes_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.bewcloud_verification_codes ADD CONSTRAINT bewcloud_verification_codes_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.bewcloud_users(id);
ALTER TABLE public.bewcloud_verification_codes OWNER TO postgres;
--
-- Name: bewcloud_dashboards; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.bewcloud_dashboards (
id uuid DEFAULT gen_random_uuid(),
@@ -71,15 +54,11 @@ CREATE TABLE public.bewcloud_dashboards (
created_at timestamp with time zone DEFAULT now()
);
ALTER TABLE public.bewcloud_dashboards OWNER TO postgres;
CREATE UNIQUE INDEX bewcloud_dashboards_unique_index ON public.bewcloud_dashboards ( user_id );
ALTER TABLE ONLY public.bewcloud_dashboards ADD CONSTRAINT bewcloud_dashboards_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.bewcloud_dashboards ADD CONSTRAINT bewcloud_dashboards_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.bewcloud_users(id);
--
-- Name: bewcloud_migrations; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.bewcloud_migrations (
id uuid DEFAULT gen_random_uuid(),
@@ -87,123 +66,4 @@ CREATE TABLE public.bewcloud_migrations (
executed_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP
);
ALTER TABLE public.bewcloud_migrations OWNER TO postgres;
--
-- Name: bewcloud_user_sessions bewcloud_user_sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.bewcloud_user_sessions
ADD CONSTRAINT bewcloud_user_sessions_pkey PRIMARY KEY (id);
--
-- Name: bewcloud_verification_codes bewcloud_verification_codes_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.bewcloud_verification_codes
ADD CONSTRAINT bewcloud_verification_codes_pkey PRIMARY KEY (id);
--
-- Name: bewcloud_users bewcloud_users_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.bewcloud_users
ADD CONSTRAINT bewcloud_users_pkey PRIMARY KEY (id);
--
-- Name: bewcloud_dashboards bewcloud_dashboards_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.bewcloud_dashboards
ADD CONSTRAINT bewcloud_dashboards_pkey PRIMARY KEY (id);
--
-- Name: bewcloud_dashboards bewcloud_dashboards_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.bewcloud_dashboards
ADD CONSTRAINT bewcloud_dashboards_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.bewcloud_users(id);
--
-- Name: bewcloud_migrations bewcloud_migrations_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.bewcloud_migrations
ADD CONSTRAINT bewcloud_migrations_pkey PRIMARY KEY (id);
--
-- Name: bewcloud_user_sessions bewcloud_user_sessions_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.bewcloud_user_sessions
ADD CONSTRAINT bewcloud_user_sessions_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.bewcloud_users(id);
--
-- Name: bewcloud_verification_codes bewcloud_verification_codes_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.bewcloud_verification_codes
ADD CONSTRAINT bewcloud_verification_codes_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.bewcloud_users(id);
--
-- Name: TABLE bewcloud_user_sessions; Type: ACL; Schema: public; Owner: postgres
--
GRANT ALL ON TABLE public.bewcloud_user_sessions TO postgres;
--
-- Name: TABLE bewcloud_users; Type: ACL; Schema: public; Owner: postgres
--
GRANT ALL ON TABLE public.bewcloud_users TO postgres;
--
-- Name: TABLE bewcloud_verification_codes; Type: ACL; Schema: public; Owner: postgres
--
GRANT ALL ON TABLE public.bewcloud_verification_codes TO postgres;
--
-- Name: TABLE bewcloud_dashboards; Type: ACL; Schema: public; Owner: postgres
--
GRANT ALL ON TABLE public.bewcloud_dashboards TO postgres;
--
-- Name: TABLE bewcloud_migrations; Type: ACL; Schema: public; Owner: postgres
--
GRANT ALL ON TABLE public.bewcloud_migrations TO postgres;
--
-- Name: DEFAULT PRIVILEGES FOR SEQUENCES; Type: DEFAULT ACL; Schema: public; Owner: postgres
--
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON SEQUENCES TO postgres;
--
-- Name: DEFAULT PRIVILEGES FOR FUNCTIONS; Type: DEFAULT ACL; Schema: public; Owner: postgres
--
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON FUNCTIONS TO postgres;
--
-- Name: DEFAULT PRIVILEGES FOR TABLES; Type: DEFAULT ACL; Schema: public; Owner: postgres
--
ALTER DEFAULT PRIVILEGES FOR ROLE postgres IN SCHEMA public GRANT ALL ON TABLES TO postgres;
ALTER TABLE ONLY public.bewcloud_migrations ADD CONSTRAINT bewcloud_migrations_pkey PRIMARY KEY (id);

View File

@@ -9,11 +9,6 @@ SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;
--
-- Name: bewcloud_news_feeds; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.bewcloud_news_feeds (
id uuid DEFAULT gen_random_uuid(),
user_id uuid DEFAULT gen_random_uuid(),
@@ -23,38 +18,11 @@ CREATE TABLE public.bewcloud_news_feeds (
created_at timestamp with time zone DEFAULT now()
);
ALTER TABLE public.bewcloud_news_feeds OWNER TO postgres;
CREATE UNIQUE INDEX bewcloud_news_feeds_unique_index ON public.bewcloud_news_feeds ( user_id, feed_url );
ALTER TABLE ONLY public.bewcloud_news_feeds ADD CONSTRAINT bewcloud_news_feeds_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.bewcloud_news_feeds ADD CONSTRAINT bewcloud_news_feeds_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.bewcloud_users(id);
--
-- Name: bewcloud_news_feeds bewcloud_news_feeds_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.bewcloud_news_feeds
ADD CONSTRAINT bewcloud_news_feeds_pkey PRIMARY KEY (id);
--
-- Name: bewcloud_news_feeds bewcloud_news_feeds_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.bewcloud_news_feeds
ADD CONSTRAINT bewcloud_news_feeds_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.bewcloud_users(id);
--
-- Name: TABLE bewcloud_news_feeds; Type: ACL; Schema: public; Owner: postgres
--
GRANT ALL ON TABLE public.bewcloud_news_feeds TO postgres;
--
-- Name: bewcloud_news_feed_articles; Type: TABLE; Schema: public; Owner: postgres
--
CREATE TABLE public.bewcloud_news_feed_articles (
id uuid DEFAULT gen_random_uuid(),
@@ -69,38 +37,8 @@ CREATE TABLE public.bewcloud_news_feed_articles (
created_at timestamp with time zone DEFAULT now()
);
ALTER TABLE public.bewcloud_news_feed_articles OWNER TO postgres;
CREATE UNIQUE INDEX bewcloud_news_feed_articles_unique_index ON public.bewcloud_news_feed_articles ( user_id, feed_id, article_url );
--
-- Name: bewcloud_news_feed_articles bewcloud_news_feed_articles_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.bewcloud_news_feed_articles
ADD CONSTRAINT bewcloud_news_feed_articles_pkey PRIMARY KEY (id);
--
-- Name: bewcloud_news_feed_articles bewcloud_news_feed_articles_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.bewcloud_news_feed_articles
ADD CONSTRAINT bewcloud_news_feed_articles_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.bewcloud_users(id);
--
-- Name: bewcloud_news_feed_articles bewcloud_news_feed_articles_feed_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres
--
ALTER TABLE ONLY public.bewcloud_news_feed_articles
ADD CONSTRAINT bewcloud_news_feed_articles_feed_id_fkey FOREIGN KEY (feed_id) REFERENCES public.bewcloud_news_feeds(id);
--
-- Name: TABLE bewcloud_news_feed_articles; Type: ACL; Schema: public; Owner: postgres
--
GRANT ALL ON TABLE public.bewcloud_news_feed_articles TO postgres;
ALTER TABLE ONLY public.bewcloud_news_feed_articles ADD CONSTRAINT bewcloud_news_feed_articles_pkey PRIMARY KEY (id);
ALTER TABLE ONLY public.bewcloud_news_feed_articles ADD CONSTRAINT bewcloud_news_feed_articles_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.bewcloud_users(id);
ALTER TABLE ONLY public.bewcloud_news_feed_articles ADD CONSTRAINT bewcloud_news_feed_articles_feed_id_fkey FOREIGN KEY (feed_id) REFERENCES public.bewcloud_news_feeds(id);

View File

@@ -25,8 +25,8 @@
"./": "./",
"xml": "https://deno.land/x/xml@2.1.3/mod.ts",
"mrmime": "https://deno.land/x/mrmime@v2.0.0/mod.ts",
"fresh/": "https://deno.land/x/fresh@1.7.1/",
"$fresh/": "https://deno.land/x/fresh@1.7.1/",
"fresh/": "https://deno.land/x/fresh@1.7.3/",
"$fresh/": "https://deno.land/x/fresh@1.7.3/",
"preact": "https://esm.sh/preact@10.23.2",
"preact/": "https://esm.sh/preact@10.23.2/",
"@preact/signals": "https://esm.sh/*@preact/signals@1.3.0",

View File

@@ -43,8 +43,11 @@ async function getMissingMigrations() {
existingMigrations.add(migrationFile.name);
}
// Sort migrations
const sortedExistingMigrations = [...existingMigrations].sort();
// Add everything to run, by default
const migrationsToExecute = new Set([...existingMigrations]);
const migrationsToExecute = new Set([...sortedExistingMigrations]);
try {
const executedMigrations = await getExecutedMigrations();