我让自己成为一个 facebook/twitter 组合只是为了好玩,但我不能 100% 确定 JDBC 的某些语义。我不确定如何将字段设置为外键或如何限制 varchar 字段中的字符数。
我的代码(带有注释以显示我需要帮助的地方)如下
(ns twitface.models.migration
(:require [clojure.java.jdbc :as sql]))
(defn create-tables []
(sql/with-connection (System/getenv "DATABASE_URL")
(do
(sql/create-table :users
[:id :serial "PRIMARY KEY"]
[:email :varchar "NOT NULL"]
[:password :varchar "NOT_NULL"]
[:full-name :varchar "NOT NULL"]
[:pref-name :varchar]
[:created_at :timestamp "NOT NULL" "DEFAULT CURRENT_TIMESTAMP"])
(sql/create-table :relations
[:id :serial "PRIMARY KEY"]
[:relating-user :numeric] ; foreign key
[:related-user :numeric] ; foreign key
[:status :varchar])
(sql/create-table :posts
[:id :serial "PRIMARY KEY"]
[:user :numeric "NOT NULL"] ; foreign key
[:destination-user :numeric "NOT NULL"] ; foreign key
[:message :varchar "NOT NULL"] ; 180 char limit
[:created_at :timestamp "NOT NULL" "DEFAULT CURRENT_TIMESTAMP"])
(sql/create-table :comments
[:id :serial "PRIMARY KEY"]
[:user :numeric "NOT NULL"] ; foreign key
[:message :varchar "NOT NULL"] ; 180 char limit
[:created_at :timestamp "NOT NULL" "DEFAULT CURRENT_TIMESTAMP"]))))
任何帮助,将不胜感激!提前致谢!