Permalink
Browse files

Warn when migrating with table named user

  • Loading branch information...
Sean Walker
Sean Walker committed Dec 22, 2018
1 parent 1a1b7a1 commit e9d69243ef0bce07966e8cb01c26a87df2013ee3
Showing with 16 additions and 5 deletions.
  1. +7 −5 src/coast/db/schema.clj
  2. +9 −0 test/coast/migrations/edn_test.clj
@@ -99,11 +99,13 @@
(map add-constraint)))

(defn create-table-if-not-exists [table]
(str "create table if not exists " table " ("
" id serial primary key,"
" updated_at timestamptz,"
" created_at timestamptz not null default now()"
" )"))
(if (= "user" table)
(throw (Exception. "user is a reserved word in postgres try a different name for this table"))
(str "create table if not exists " table " ("
" id serial primary key,"
" updated_at timestamptz,"
" created_at timestamptz not null default now()"
" )")))

(defn create-tables-if-not-exists [v]
(let [idents (->> (filter ident? v)
@@ -0,0 +1,9 @@
(ns coast.migrations.edn-test
(:require [coast.migrations.edn :as migrations.edn]
[clojure.test :refer :all]))

(deftest migrate
(testing "migrate with user table"
(with-redefs [migrations.edn/content (fn [s] [{:db/ident :user/name :db/type "text"}])]
(is (thrown-with-msg? Exception #"user is a reserved word in postgres try a different name for this table"
(migrations.edn/migrate ""))))))

0 comments on commit e9d6924

Please sign in to comment.