diff --git a/.buildpacks b/.buildpacks index f3661dc45b7..8a2a37ab144 100644 --- a/.buildpacks +++ b/.buildpacks @@ -1,4 +1,5 @@ https://github.com/rcaught/heroku-buildpack-cmake#e4e2c9e -https://github.com/emk/heroku-buildpack-rust#035823 +https://github.com/mmirate/heroku-buildpack-rust#f1cf6643e https://github.com/tonycoco/heroku-buildpack-ember-cli https://github.com/ryandotsmith/nginx-buildpack.git#af813ba +https://github.com/sgrif/heroku-buildpack-diesel#43267f2 diff --git a/.travis.yml b/.travis.yml index 93cda0f4ad7..2493e7bb282 100644 --- a/.travis.yml +++ b/.travis.yml @@ -17,9 +17,10 @@ install: - pip install 'travis-cargo<0.2' --user && export PATH=$HOME/.local/bin:$PATH - yarn - yarn run bower install + - cargo install diesel_cli --debug --no-default-features --features postgres && export PATH=$HOME/.cargo/bin:$PATH before_script: - - psql -c 'create database cargo_registry_test;' -U postgres + - diesel database setup script: - cargo build @@ -42,6 +43,7 @@ addons: env: global: + - DATABASE_URL=postgres://postgres:@localhost/cargo_registry_test - TEST_DATABASE_URL=postgres://postgres:@localhost/cargo_registry_test - S3_BUCKET=alexcrichton-test diff --git a/Cargo.lock b/Cargo.lock index b6dd8c42084..bd4f34a9c2e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -15,6 +15,9 @@ dependencies = [ "conduit-static 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "conduit-test 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "curl 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "diesel 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)", + "diesel_codegen 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "diesel_full_text_search 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "dotenv 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "flate2 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)", @@ -26,6 +29,7 @@ dependencies = [ "openssl 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)", "postgres 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)", "r2d2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "r2d2-diesel 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "r2d2_postgres 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", @@ -72,6 +76,11 @@ name = "byteorder" version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "byteorder" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "civet" version = "0.9.0" @@ -249,6 +258,46 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "diesel" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "pq-sys 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 0.9.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "diesel_codegen" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "diesel 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)", + "diesel_infer_schema 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "dotenv 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.11.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "diesel_full_text_search" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "diesel 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "diesel_infer_schema" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "diesel 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.11.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "dotenv" version = "0.8.0" @@ -257,6 +306,11 @@ dependencies = [ "regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dtoa" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "env_logger" version = "0.4.0" @@ -335,6 +389,11 @@ dependencies = [ "unicode-normalization 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "itoa" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "kernel32-sys" version = "0.2.2" @@ -453,6 +512,11 @@ dependencies = [ "libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "num-traits" +version = "0.1.37" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "oauth2" version = "0.3.0" @@ -547,6 +611,16 @@ dependencies = [ "time 0.1.36 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "pq-sys" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "quote" +version = "0.3.14" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "r2d2" version = "0.7.1" @@ -556,6 +630,15 @@ dependencies = [ "log 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "r2d2-diesel" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "diesel 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)", + "r2d2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "r2d2_postgres" version = "0.11.1" @@ -649,6 +732,40 @@ dependencies = [ "regex 0.1.80 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "serde" +version = "0.9.11" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "serde_json" +version = "0.9.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "syn" +version = "0.11.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "quote 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "synom" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "thread-id" version = "2.0.0" @@ -716,6 +833,11 @@ name = "unicode-normalization" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "unicode-xid" +version = "0.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "unreachable" version = "0.1.1" @@ -774,6 +896,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum bitflags 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aad18937a628ec6abcd26d1489012cc0e18c21798210f491af69ded9b881106d" "checksum bufstream 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7b48dbe2ff0e98fa2f03377d204a9637d3c9816cd431bfe05a8abbd0ea11d074" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" +"checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" "checksum civet 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d8158a63bb12df912168a638a0a4e2de5d50f587b9fa20b2f7aeb85433a8c926" "checksum civet-sys 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "958d15372bf28b7983cb35e1d4bf36dd843b0d42e507c1c73aad7150372c5936" "checksum cmake 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "a3a6805df695087e7c1bcd9a82e03ad6fb864c8e67ac41b1348229ce5b7f0407" @@ -792,7 +915,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cookie 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8d12191219481eb202e05529f646f9af8d1ecfcd53bbf3997d4a4b15ca095cf8" "checksum curl 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "52f97f136f098f09c5d377e150afde7b29f43690cd1d80edb71409fda11c904e" "checksum curl-sys 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ec50c305e9de46198e8911556355f4aea46f2002cb25d2388d421404e91b60d9" +"checksum diesel 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)" = "2f872f59c19519db52506648a00d18ec5e3aa81eb99710f6837715eae41f3c76" +"checksum diesel_codegen 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bf8115b73ca2640b8c6abdb0e34fd80f05cd8a7fee92067ba17d24448db8db5b" +"checksum diesel_full_text_search 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7bd6a9d8f3c1a87fef80454adf60ce10985502b3e950eeb83058da23405504b1" +"checksum diesel_infer_schema 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5573f6506105cfbca35d69fccc9ab8d6dc41d54a58fe18c9f9011abe3284b4a4" "checksum dotenv 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eea1395d2df3b5344dc577809296d9578303296e8d105c408aa80ed67d598ef1" +"checksum dtoa 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "80c8b71fd71146990a9742fc06dcbbde19161a267e0ad4e572c35162f4578c90" "checksum env_logger 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "99971fb1b635fe7a0ee3c4d065845bb93cca80a23b5613b5613391ece5de4144" "checksum error-chain 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "318cb3c71ee4cdea69fdc9e15c173b245ed6063e1709029e8fd32525a881120f" "checksum fallible-iterator 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5d48ab1bc11a086628e8cc0cc2c2dc200b884ac05c4b48fb71d6036b6999ff1d" @@ -803,6 +931,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum git2 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "046ae03385257040b2a35e56d9669d950dd911ba2bf48202fbef73ee6aab27b2" "checksum hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d6a22814455d41612f41161581c2883c0c6a1c41852729b17d5ed88f01e153aa" "checksum idna 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1053236e00ce4f668aeca4a769a09b3bf5a682d802abd6f3cb39374f6b162c11" +"checksum itoa 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eb2f404fbc66fd9aac13e998248505e7ecb2ad8e44ab6388684c5fb11c6c251c" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum lazy_static 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6abe0ee2e758cd6bc8a2cd56726359007748fbf4128da998b65d0b70f881e19b" "checksum libc 0.2.20 (registry+https://github.com/rust-lang/crates.io-index)" = "684f330624d8c3784fb9558ca46c4ce488073a8d22450415c5eb4f4cfb0d11b5" @@ -817,6 +946,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum memchr 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1dbccc0e46f1ea47b9f17e6d67c5a96bd27030519c519c9c91327e31275a47b4" "checksum metadeps 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "829fffe7ea1d747e23f64be972991bc516b2f1ac2ae4a3b33d8bea150c410151" "checksum miniz-sys 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "28eaee17666671fa872e567547e8428e83308ebe5808cdf6a0e28397dbe2c726" +"checksum num-traits 0.1.37 (registry+https://github.com/rust-lang/crates.io-index)" = "e1cbfa3781f3fe73dc05321bed52a06d2d491eaa764c52335cf4399f046ece99" "checksum oauth2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f4fcd990d45681b9eba5f4f3fa7d0371ec277f4e4380a94104d26aa4fae386fc" "checksum openssl 0.9.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0c00da69323449142e00a5410f0e022b39e8bbb7dc569cee8fc6af279279483c" "checksum openssl-probe 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "756d49c8424483a3df3b5d735112b4da22109ced9a8294f1f5cdf80fb3810919" @@ -827,7 +957,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum postgres 0.13.5 (registry+https://github.com/rust-lang/crates.io-index)" = "585ca978431cddac0aa926246f18fe30a47401eabbe9bbda573dc60389c10ea1" "checksum postgres-protocol 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "283e27d237a5772ef00c9e3f97e632f9a565ff514761af3e88e129576af7077c" "checksum postgres-shared 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6f09b8819c2586032ed23bfbe95f6edfbebdc18bf9d0fe02c1f785f659958fbb" +"checksum pq-sys 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b8b9304824c6f013d5cb3db2e3e4fbb07379dec552afaae67b652a0f20adf0ec" +"checksum quote 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "7375cf7ad34a92e8fd18dd9c42f58b9a11def59ab48bec955bf359a788335592" "checksum r2d2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ecfed1b03be2e66624ec87cef173dad54253f25405bd3c918b321e4dda3ad32" +"checksum r2d2-diesel 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1549332d11a91ac5b944a65fd59b9fe5ead091260556ae427b6919dadb08cace" "checksum r2d2_postgres 0.11.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d9ea3d4773725bf025184675ad9c7328609e8e4ddd27557dd0b67fff29bf2c2f" "checksum rand 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "022e0636ec2519ddae48154b028864bdce4eaf7d35226ab8e65c611be97b189d" "checksum redox_syscall 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd35cc9a8bdec562c757e3d43c1526b5c6d2653e23e2315065bc25556550753" @@ -839,6 +972,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rustc-serialize 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "237546c689f20bb44980270c73c3b9edd0891c1be49cc1274406134a66d3957b" "checksum semver 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ae2ff60ecdb19c255841c066cbfa5f8c2a4ada1eb3ae47c77ab6667128da71f5" "checksum semver-parser 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d8fff3c9c5a54636ab95acd8c1349926e04cb1eb8cd70b5adced8a1d1f703a67" +"checksum serde 0.9.11 (registry+https://github.com/rust-lang/crates.io-index)" = "a702319c807c016e51f672e5c77d6f0b46afddd744b5e437d6b8436b888b458f" +"checksum serde_json 0.9.9 (registry+https://github.com/rust-lang/crates.io-index)" = "dbc45439552eb8fb86907a2c41c1fd0ef97458efb87ff7f878db466eb581824e" +"checksum syn 0.11.8 (registry+https://github.com/rust-lang/crates.io-index)" = "37c279fb816210c9bb28b2c292664581e7b87b4561e86b94df462664d8620bb8" +"checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum thread-id 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9539db560102d1cef46b8b78ce737ff0bb64e7e18d35b2a5688f7d097d0ff03" "checksum thread-id 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4437c97558c70d129e40629a5b385b3fb1ffac301e63941335e4d354081ec14a" "checksum thread_local 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "8576dbbfcaef9641452d5cf0df9b0e7eeab7694956dd33bb61515fb8f18cfdd5" @@ -847,6 +984,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum toml 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "736b60249cb25337bc196faa43ee12c705e426f3d55c214d73a4e7be06f92cb4" "checksum unicode-bidi 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "b61814f3e7fd0e0f15370f767c7c943e08bc2e3214233ae8f88522b334ceb778" "checksum unicode-normalization 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5e94e9f6961090fcc75180629c4ef33e5310d6ed2c0dd173f4ca63c9043b669e" +"checksum unicode-xid 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f860d7d29cf02cb2f3f359fd35991af3d30bac52c57d265a3c461074cb4dc" "checksum unreachable 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1f2ae5ddb18e1c92664717616dd9549dde73f539f01bd7b77c2edb2446bdff91" "checksum url 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f5ba8a749fb4479b043733416c244fa9d1d3af3d7c23804944651c8a448cb87e" "checksum user32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ef4711d107b21b410a3a974b1204d9accc8b10dad75d8324b5d755de1617d47" diff --git a/Cargo.toml b/Cargo.toml index 50d6f6e3e3e..dfb0f31029c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,6 +36,10 @@ rustc-serialize = "0.3" license-exprs = "^1.3" dotenv = "0.8.0" toml = "0.2" +diesel = { version = "0.11.0", features = ["postgres", "serde_json"] } +diesel_codegen = { version = "0.11.0", features = ["postgres"] } +r2d2-diesel = "0.11.0" +diesel_full_text_search = "0.11.0" conduit = "0.8" conduit-conditional-get = "0.8" diff --git a/Procfile b/Procfile index d3b205e2916..b4fa48bf1c3 100644 --- a/Procfile +++ b/Procfile @@ -1,2 +1,2 @@ -web: ./target/release/migrate && bin/start-nginx ./target/release/server +web: ./target/release/migrate && bin/diesel migration run && bin/start-nginx ./target/release/server worker: ./target/release/update-downloads daemon 300 diff --git a/README.md b/README.md index 4786fd9c2c4..6ffda7384ff 100644 --- a/README.md +++ b/README.md @@ -82,6 +82,9 @@ After cloning the repo, do the following: 2. Copy the `.env.sample` file to `.env`. Some settings will need to be modified. These instructions are in the subsequent sections. +3. Install `diesel_cli` using `cargo install diesel_cli --no-default-features + --features postgres`. + ### Running Tests After following the above instructions: @@ -158,7 +161,7 @@ After following the instructions described in "Working on the Backend": 5. Run the migrations: ``` - ./target/debug/migrate + diesel migration run ``` 6. Start the backend server: diff --git a/migrations/20140924113530_dumped_migration_1/down.sql b/migrations/20140924113530_dumped_migration_1/down.sql new file mode 100644 index 00000000000..441087ad7e1 --- /dev/null +++ b/migrations/20140924113530_dumped_migration_1/down.sql @@ -0,0 +1 @@ +DROP TABLE users; \ No newline at end of file diff --git a/migrations/20140924113530_dumped_migration_1/up.sql b/migrations/20140924113530_dumped_migration_1/up.sql new file mode 100644 index 00000000000..84c269232ac --- /dev/null +++ b/migrations/20140924113530_dumped_migration_1/up.sql @@ -0,0 +1,6 @@ +CREATE TABLE users ( + id SERIAL PRIMARY KEY, + email VARCHAR NOT NULL UNIQUE, + gh_access_token VARCHAR NOT NULL, + api_token VARCHAR NOT NULL + ); \ No newline at end of file diff --git a/migrations/20140924114003_dumped_migration_2/down.sql b/migrations/20140924114003_dumped_migration_2/down.sql new file mode 100644 index 00000000000..3f026bd2648 --- /dev/null +++ b/migrations/20140924114003_dumped_migration_2/down.sql @@ -0,0 +1 @@ +DROP TABLE packages; \ No newline at end of file diff --git a/migrations/20140924114003_dumped_migration_2/up.sql b/migrations/20140924114003_dumped_migration_2/up.sql new file mode 100644 index 00000000000..e85f21a7ca3 --- /dev/null +++ b/migrations/20140924114003_dumped_migration_2/up.sql @@ -0,0 +1,5 @@ +CREATE TABLE packages ( + id SERIAL PRIMARY KEY, + name VARCHAR NOT NULL UNIQUE, + user_id INTEGER NOT NULL + ); \ No newline at end of file diff --git a/migrations/20140924114059_dumped_migration_3/down.sql b/migrations/20140924114059_dumped_migration_3/down.sql new file mode 100644 index 00000000000..77aac97e06c --- /dev/null +++ b/migrations/20140924114059_dumped_migration_3/down.sql @@ -0,0 +1 @@ +DROP TABLE versions; \ No newline at end of file diff --git a/migrations/20140924114059_dumped_migration_3/up.sql b/migrations/20140924114059_dumped_migration_3/up.sql new file mode 100644 index 00000000000..e5882b57aff --- /dev/null +++ b/migrations/20140924114059_dumped_migration_3/up.sql @@ -0,0 +1,5 @@ +CREATE TABLE versions ( + id SERIAL PRIMARY KEY, + package_id INTEGER NOT NULL, + num VARCHAR NOT NULL + ); \ No newline at end of file diff --git a/migrations/20140924115329_dumped_migration_4/down.sql b/migrations/20140924115329_dumped_migration_4/down.sql new file mode 100644 index 00000000000..adf7e7b5a6a --- /dev/null +++ b/migrations/20140924115329_dumped_migration_4/down.sql @@ -0,0 +1 @@ +ALTER TABLE versions DROP CONSTRAINT unique_num; \ No newline at end of file diff --git a/migrations/20140924115329_dumped_migration_4/up.sql b/migrations/20140924115329_dumped_migration_4/up.sql new file mode 100644 index 00000000000..c7cfcf79105 --- /dev/null +++ b/migrations/20140924115329_dumped_migration_4/up.sql @@ -0,0 +1 @@ +ALTER TABLE versions ADD CONSTRAINT unique_num UNIQUE (package_id, num); \ No newline at end of file diff --git a/migrations/20140924120803_dumped_migration_5/down.sql b/migrations/20140924120803_dumped_migration_5/down.sql new file mode 100644 index 00000000000..44bb6f74770 --- /dev/null +++ b/migrations/20140924120803_dumped_migration_5/down.sql @@ -0,0 +1 @@ +DROP TABLE version_dependencies; \ No newline at end of file diff --git a/migrations/20140924120803_dumped_migration_5/up.sql b/migrations/20140924120803_dumped_migration_5/up.sql new file mode 100644 index 00000000000..12ad9633b03 --- /dev/null +++ b/migrations/20140924120803_dumped_migration_5/up.sql @@ -0,0 +1,4 @@ +CREATE TABLE version_dependencies ( + version_id INTEGER NOT NULL, + depends_on_id INTEGER NOT NULL + ); \ No newline at end of file diff --git a/migrations/20140925132248_dumped_migration_6/down.sql b/migrations/20140925132248_dumped_migration_6/down.sql new file mode 100644 index 00000000000..29266be4da0 --- /dev/null +++ b/migrations/20140925132248_dumped_migration_6/down.sql @@ -0,0 +1 @@ +ALTER TABLE packages DROP COLUMN updated_at; \ No newline at end of file diff --git a/migrations/20140925132248_dumped_migration_6/up.sql b/migrations/20140925132248_dumped_migration_6/up.sql new file mode 100644 index 00000000000..07910471cd4 --- /dev/null +++ b/migrations/20140925132248_dumped_migration_6/up.sql @@ -0,0 +1 @@ +ALTER TABLE packages ADD COLUMN updated_at TIMESTAMP NOT NULL DEFAULT now(); \ No newline at end of file diff --git a/migrations/20140925132249_dumped_migration_7/down.sql b/migrations/20140925132249_dumped_migration_7/down.sql new file mode 100644 index 00000000000..633275f141c --- /dev/null +++ b/migrations/20140925132249_dumped_migration_7/down.sql @@ -0,0 +1 @@ +ALTER TABLE packages DROP COLUMN created_at; \ No newline at end of file diff --git a/migrations/20140925132249_dumped_migration_7/up.sql b/migrations/20140925132249_dumped_migration_7/up.sql new file mode 100644 index 00000000000..b08637fd7d8 --- /dev/null +++ b/migrations/20140925132249_dumped_migration_7/up.sql @@ -0,0 +1 @@ +ALTER TABLE packages ADD COLUMN created_at TIMESTAMP NOT NULL DEFAULT now(); \ No newline at end of file diff --git a/migrations/20140925132250_dumped_migration_8/down.sql b/migrations/20140925132250_dumped_migration_8/down.sql new file mode 100644 index 00000000000..e69de29bb2d diff --git a/migrations/20140925132250_dumped_migration_8/up.sql b/migrations/20140925132250_dumped_migration_8/up.sql new file mode 100644 index 00000000000..7d8825621e0 --- /dev/null +++ b/migrations/20140925132250_dumped_migration_8/up.sql @@ -0,0 +1,2 @@ +UPDATE packages SET updated_at = now() WHERE updated_at IS NULL; +UPDATE packages SET created_at = now() WHERE created_at IS NULL; \ No newline at end of file diff --git a/migrations/20140925132251_dumped_migration_9/down.sql b/migrations/20140925132251_dumped_migration_9/down.sql new file mode 100644 index 00000000000..a7c052cc69d --- /dev/null +++ b/migrations/20140925132251_dumped_migration_9/down.sql @@ -0,0 +1 @@ +ALTER TABLE versions DROP COLUMN updated_at; \ No newline at end of file diff --git a/migrations/20140925132251_dumped_migration_9/up.sql b/migrations/20140925132251_dumped_migration_9/up.sql new file mode 100644 index 00000000000..0a916c4971d --- /dev/null +++ b/migrations/20140925132251_dumped_migration_9/up.sql @@ -0,0 +1 @@ +ALTER TABLE versions ADD COLUMN updated_at TIMESTAMP NOT NULL DEFAULT now(); \ No newline at end of file diff --git a/migrations/20140925132252_dumped_migration_10/down.sql b/migrations/20140925132252_dumped_migration_10/down.sql new file mode 100644 index 00000000000..35e9c87224d --- /dev/null +++ b/migrations/20140925132252_dumped_migration_10/down.sql @@ -0,0 +1 @@ +ALTER TABLE versions DROP COLUMN created_at; \ No newline at end of file diff --git a/migrations/20140925132252_dumped_migration_10/up.sql b/migrations/20140925132252_dumped_migration_10/up.sql new file mode 100644 index 00000000000..54c8a895ec0 --- /dev/null +++ b/migrations/20140925132252_dumped_migration_10/up.sql @@ -0,0 +1 @@ +ALTER TABLE versions ADD COLUMN created_at TIMESTAMP NOT NULL DEFAULT now(); \ No newline at end of file diff --git a/migrations/20140925132253_dumped_migration_11/down.sql b/migrations/20140925132253_dumped_migration_11/down.sql new file mode 100644 index 00000000000..e69de29bb2d diff --git a/migrations/20140925132253_dumped_migration_11/up.sql b/migrations/20140925132253_dumped_migration_11/up.sql new file mode 100644 index 00000000000..941f71b3412 --- /dev/null +++ b/migrations/20140925132253_dumped_migration_11/up.sql @@ -0,0 +1,2 @@ +UPDATE versions SET updated_at = now() WHERE updated_at IS NULL; +UPDATE versions SET created_at = now() WHERE created_at IS NULL; \ No newline at end of file diff --git a/migrations/20140925132254_dumped_migration_12/down.sql b/migrations/20140925132254_dumped_migration_12/down.sql new file mode 100644 index 00000000000..e69de29bb2d diff --git a/migrations/20140925132254_dumped_migration_12/up.sql b/migrations/20140925132254_dumped_migration_12/up.sql new file mode 100644 index 00000000000..66f2dd3f07c --- /dev/null +++ b/migrations/20140925132254_dumped_migration_12/up.sql @@ -0,0 +1,4 @@ +ALTER TABLE versions ALTER COLUMN updated_at DROP DEFAULT; +ALTER TABLE versions ALTER COLUMN created_at DROP DEFAULT; +ALTER TABLE packages ALTER COLUMN updated_at DROP DEFAULT; +ALTER TABLE packages ALTER COLUMN created_at DROP DEFAULT; \ No newline at end of file diff --git a/migrations/20140925153704_dumped_migration_13/down.sql b/migrations/20140925153704_dumped_migration_13/down.sql new file mode 100644 index 00000000000..cd4c6244c2b --- /dev/null +++ b/migrations/20140925153704_dumped_migration_13/down.sql @@ -0,0 +1 @@ +DROP TABLE metadata; \ No newline at end of file diff --git a/migrations/20140925153704_dumped_migration_13/up.sql b/migrations/20140925153704_dumped_migration_13/up.sql new file mode 100644 index 00000000000..08b10cf132d --- /dev/null +++ b/migrations/20140925153704_dumped_migration_13/up.sql @@ -0,0 +1,3 @@ +CREATE TABLE metadata ( + total_downloads BIGINT NOT NULL + ); \ No newline at end of file diff --git a/migrations/20140925153705_dumped_migration_14/down.sql b/migrations/20140925153705_dumped_migration_14/down.sql new file mode 100644 index 00000000000..e6a9a872b94 --- /dev/null +++ b/migrations/20140925153705_dumped_migration_14/down.sql @@ -0,0 +1 @@ +DELETE FROM metadata; \ No newline at end of file diff --git a/migrations/20140925153705_dumped_migration_14/up.sql b/migrations/20140925153705_dumped_migration_14/up.sql new file mode 100644 index 00000000000..f4d3faad874 --- /dev/null +++ b/migrations/20140925153705_dumped_migration_14/up.sql @@ -0,0 +1 @@ +INSERT INTO metadata (total_downloads) VALUES (0); \ No newline at end of file diff --git a/migrations/20140925161623_dumped_migration_15/down.sql b/migrations/20140925161623_dumped_migration_15/down.sql new file mode 100644 index 00000000000..4480f4455aa --- /dev/null +++ b/migrations/20140925161623_dumped_migration_15/down.sql @@ -0,0 +1 @@ +ALTER TABLE packages DROP COLUMN downloads; \ No newline at end of file diff --git a/migrations/20140925161623_dumped_migration_15/up.sql b/migrations/20140925161623_dumped_migration_15/up.sql new file mode 100644 index 00000000000..2c0bc2ca0e1 --- /dev/null +++ b/migrations/20140925161623_dumped_migration_15/up.sql @@ -0,0 +1 @@ +ALTER TABLE packages ADD COLUMN downloads INTEGER NOT NULL DEFAULT 0; \ No newline at end of file diff --git a/migrations/20140925161624_dumped_migration_16/down.sql b/migrations/20140925161624_dumped_migration_16/down.sql new file mode 100644 index 00000000000..d688732df6e --- /dev/null +++ b/migrations/20140925161624_dumped_migration_16/down.sql @@ -0,0 +1 @@ +ALTER TABLE versions DROP COLUMN downloads; \ No newline at end of file diff --git a/migrations/20140925161624_dumped_migration_16/up.sql b/migrations/20140925161624_dumped_migration_16/up.sql new file mode 100644 index 00000000000..1bc3bfb0991 --- /dev/null +++ b/migrations/20140925161624_dumped_migration_16/up.sql @@ -0,0 +1 @@ +ALTER TABLE versions ADD COLUMN downloads INTEGER NOT NULL DEFAULT 0; \ No newline at end of file diff --git a/migrations/20140925161625_dumped_migration_17/down.sql b/migrations/20140925161625_dumped_migration_17/down.sql new file mode 100644 index 00000000000..e69de29bb2d diff --git a/migrations/20140925161625_dumped_migration_17/up.sql b/migrations/20140925161625_dumped_migration_17/up.sql new file mode 100644 index 00000000000..7890d32ef76 --- /dev/null +++ b/migrations/20140925161625_dumped_migration_17/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE versions ALTER COLUMN downloads DROP DEFAULT; +ALTER TABLE packages ALTER COLUMN downloads DROP DEFAULT; \ No newline at end of file diff --git a/migrations/20140926130044_dumped_migration_18/down.sql b/migrations/20140926130044_dumped_migration_18/down.sql new file mode 100644 index 00000000000..219648b6a4e --- /dev/null +++ b/migrations/20140926130044_dumped_migration_18/down.sql @@ -0,0 +1 @@ +ALTER TABLE packages DROP COLUMN max_version; \ No newline at end of file diff --git a/migrations/20140926130044_dumped_migration_18/up.sql b/migrations/20140926130044_dumped_migration_18/up.sql new file mode 100644 index 00000000000..878886511a0 --- /dev/null +++ b/migrations/20140926130044_dumped_migration_18/up.sql @@ -0,0 +1 @@ +ALTER TABLE packages ADD COLUMN max_version VARCHAR; \ No newline at end of file diff --git a/migrations/20140926130046_dumped_migration_19/down.sql b/migrations/20140926130046_dumped_migration_19/down.sql new file mode 100644 index 00000000000..d0b5aa1927e --- /dev/null +++ b/migrations/20140926130046_dumped_migration_19/down.sql @@ -0,0 +1 @@ +ALTER TABLE versions ALTER COLUMN downloads DROP NOT NULL; \ No newline at end of file diff --git a/migrations/20140926130046_dumped_migration_19/up.sql b/migrations/20140926130046_dumped_migration_19/up.sql new file mode 100644 index 00000000000..569a2f79d82 --- /dev/null +++ b/migrations/20140926130046_dumped_migration_19/up.sql @@ -0,0 +1 @@ +ALTER TABLE versions ALTER COLUMN downloads SET NOT NULL; \ No newline at end of file diff --git a/migrations/20140926174020_dumped_migration_20/down.sql b/migrations/20140926174020_dumped_migration_20/down.sql new file mode 100644 index 00000000000..f674a6466ac --- /dev/null +++ b/migrations/20140926174020_dumped_migration_20/down.sql @@ -0,0 +1,2 @@ +ALTER TABLE crates RENAME TO packages; +ALTER TABLE versions RENAME COLUMN crate_id TO package_id; \ No newline at end of file diff --git a/migrations/20140926174020_dumped_migration_20/up.sql b/migrations/20140926174020_dumped_migration_20/up.sql new file mode 100644 index 00000000000..4944284c34b --- /dev/null +++ b/migrations/20140926174020_dumped_migration_20/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE packages RENAME TO crates; +ALTER TABLE versions RENAME COLUMN package_id TO crate_id; \ No newline at end of file diff --git a/migrations/20140929103749_dumped_migration_21/down.sql b/migrations/20140929103749_dumped_migration_21/down.sql new file mode 100644 index 00000000000..d4e105a6b16 --- /dev/null +++ b/migrations/20140929103749_dumped_migration_21/down.sql @@ -0,0 +1 @@ +DROP INDEX index_crate_updated_at; \ No newline at end of file diff --git a/migrations/20140929103749_dumped_migration_21/up.sql b/migrations/20140929103749_dumped_migration_21/up.sql new file mode 100644 index 00000000000..c8a0da59817 --- /dev/null +++ b/migrations/20140929103749_dumped_migration_21/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_crate_updated_at ON crates (updated_at); \ No newline at end of file diff --git a/migrations/20140929103750_dumped_migration_22/down.sql b/migrations/20140929103750_dumped_migration_22/down.sql new file mode 100644 index 00000000000..ee9e8e81df0 --- /dev/null +++ b/migrations/20140929103750_dumped_migration_22/down.sql @@ -0,0 +1 @@ +DROP INDEX index_crate_created_at; \ No newline at end of file diff --git a/migrations/20140929103750_dumped_migration_22/up.sql b/migrations/20140929103750_dumped_migration_22/up.sql new file mode 100644 index 00000000000..db85a347e34 --- /dev/null +++ b/migrations/20140929103750_dumped_migration_22/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_crate_created_at ON crates (created_at); \ No newline at end of file diff --git a/migrations/20140929103751_dumped_migration_23/down.sql b/migrations/20140929103751_dumped_migration_23/down.sql new file mode 100644 index 00000000000..89022d6c2f5 --- /dev/null +++ b/migrations/20140929103751_dumped_migration_23/down.sql @@ -0,0 +1 @@ +DROP INDEX index_crate_downloads; \ No newline at end of file diff --git a/migrations/20140929103751_dumped_migration_23/up.sql b/migrations/20140929103751_dumped_migration_23/up.sql new file mode 100644 index 00000000000..f375bce26d2 --- /dev/null +++ b/migrations/20140929103751_dumped_migration_23/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_crate_downloads ON crates (downloads); \ No newline at end of file diff --git a/migrations/20140929103752_dumped_migration_24/down.sql b/migrations/20140929103752_dumped_migration_24/down.sql new file mode 100644 index 00000000000..03aef0ef5dd --- /dev/null +++ b/migrations/20140929103752_dumped_migration_24/down.sql @@ -0,0 +1 @@ +DROP INDEX index_version_crate_id; \ No newline at end of file diff --git a/migrations/20140929103752_dumped_migration_24/up.sql b/migrations/20140929103752_dumped_migration_24/up.sql new file mode 100644 index 00000000000..4958904620b --- /dev/null +++ b/migrations/20140929103752_dumped_migration_24/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_version_crate_id ON versions (crate_id); \ No newline at end of file diff --git a/migrations/20140929103753_dumped_migration_25/down.sql b/migrations/20140929103753_dumped_migration_25/down.sql new file mode 100644 index 00000000000..b86f734234d --- /dev/null +++ b/migrations/20140929103753_dumped_migration_25/down.sql @@ -0,0 +1 @@ +DROP INDEX index_version_num; \ No newline at end of file diff --git a/migrations/20140929103753_dumped_migration_25/up.sql b/migrations/20140929103753_dumped_migration_25/up.sql new file mode 100644 index 00000000000..dc1df285c00 --- /dev/null +++ b/migrations/20140929103753_dumped_migration_25/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_version_num ON versions (num); \ No newline at end of file diff --git a/migrations/20140929103754_dumped_migration_26/down.sql b/migrations/20140929103754_dumped_migration_26/down.sql new file mode 100644 index 00000000000..643dd2c238c --- /dev/null +++ b/migrations/20140929103754_dumped_migration_26/down.sql @@ -0,0 +1 @@ +DROP INDEX index_version_dependencies_version_id; \ No newline at end of file diff --git a/migrations/20140929103754_dumped_migration_26/up.sql b/migrations/20140929103754_dumped_migration_26/up.sql new file mode 100644 index 00000000000..98092fb60d8 --- /dev/null +++ b/migrations/20140929103754_dumped_migration_26/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_version_dependencies_version_id ON version_dependencies (version_id); \ No newline at end of file diff --git a/migrations/20140929103755_dumped_migration_27/down.sql b/migrations/20140929103755_dumped_migration_27/down.sql new file mode 100644 index 00000000000..245e722a839 --- /dev/null +++ b/migrations/20140929103755_dumped_migration_27/down.sql @@ -0,0 +1 @@ +DROP INDEX index_version_dependencies_depends_on_id; \ No newline at end of file diff --git a/migrations/20140929103755_dumped_migration_27/up.sql b/migrations/20140929103755_dumped_migration_27/up.sql new file mode 100644 index 00000000000..ec06663efd6 --- /dev/null +++ b/migrations/20140929103755_dumped_migration_27/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_version_dependencies_depends_on_id ON version_dependencies (depends_on_id); \ No newline at end of file diff --git a/migrations/20140929103756_dumped_migration_28/down.sql b/migrations/20140929103756_dumped_migration_28/down.sql new file mode 100644 index 00000000000..705a88c9790 --- /dev/null +++ b/migrations/20140929103756_dumped_migration_28/down.sql @@ -0,0 +1 @@ +DROP TABLE crate_downloads; \ No newline at end of file diff --git a/migrations/20140929103756_dumped_migration_28/up.sql b/migrations/20140929103756_dumped_migration_28/up.sql new file mode 100644 index 00000000000..07fd783bd24 --- /dev/null +++ b/migrations/20140929103756_dumped_migration_28/up.sql @@ -0,0 +1,6 @@ +CREATE TABLE crate_downloads ( + id SERIAL PRIMARY KEY, + crate_id INTEGER NOT NULL, + downloads INTEGER NOT NULL, + date TIMESTAMP NOT NULL + ); \ No newline at end of file diff --git a/migrations/20140929103757_dumped_migration_29/down.sql b/migrations/20140929103757_dumped_migration_29/down.sql new file mode 100644 index 00000000000..a429ff3694b --- /dev/null +++ b/migrations/20140929103757_dumped_migration_29/down.sql @@ -0,0 +1 @@ +DROP INDEX index_crate_downloads_crate_id; \ No newline at end of file diff --git a/migrations/20140929103757_dumped_migration_29/up.sql b/migrations/20140929103757_dumped_migration_29/up.sql new file mode 100644 index 00000000000..612090957ff --- /dev/null +++ b/migrations/20140929103757_dumped_migration_29/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_crate_downloads_crate_id ON crate_downloads (crate_id); \ No newline at end of file diff --git a/migrations/20140929103758_dumped_migration_30/down.sql b/migrations/20140929103758_dumped_migration_30/down.sql new file mode 100644 index 00000000000..077ab719867 --- /dev/null +++ b/migrations/20140929103758_dumped_migration_30/down.sql @@ -0,0 +1 @@ +DROP INDEX index_crate_downloads_date; \ No newline at end of file diff --git a/migrations/20140929103758_dumped_migration_30/up.sql b/migrations/20140929103758_dumped_migration_30/up.sql new file mode 100644 index 00000000000..1dd28bcf260 --- /dev/null +++ b/migrations/20140929103758_dumped_migration_30/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_crate_downloads_date ON crate_downloads (date(date)); \ No newline at end of file diff --git a/migrations/20140929103759_dumped_migration_31/down.sql b/migrations/20140929103759_dumped_migration_31/down.sql new file mode 100644 index 00000000000..f7698240aba --- /dev/null +++ b/migrations/20140929103759_dumped_migration_31/down.sql @@ -0,0 +1 @@ +DROP TABLE version_downloads; \ No newline at end of file diff --git a/migrations/20140929103759_dumped_migration_31/up.sql b/migrations/20140929103759_dumped_migration_31/up.sql new file mode 100644 index 00000000000..06fc6406376 --- /dev/null +++ b/migrations/20140929103759_dumped_migration_31/up.sql @@ -0,0 +1,8 @@ +CREATE TABLE version_downloads ( + id SERIAL PRIMARY KEY, + version_id INTEGER NOT NULL, + downloads INTEGER NOT NULL, + counted INTEGER NOT NULL, + date TIMESTAMP NOT NULL, + processed BOOLEAN NOT NULL + ); \ No newline at end of file diff --git a/migrations/20140929103760_dumped_migration_32/down.sql b/migrations/20140929103760_dumped_migration_32/down.sql new file mode 100644 index 00000000000..c18d6ae6608 --- /dev/null +++ b/migrations/20140929103760_dumped_migration_32/down.sql @@ -0,0 +1 @@ +DROP INDEX index_version_downloads_version_id; \ No newline at end of file diff --git a/migrations/20140929103760_dumped_migration_32/up.sql b/migrations/20140929103760_dumped_migration_32/up.sql new file mode 100644 index 00000000000..e23030225d3 --- /dev/null +++ b/migrations/20140929103760_dumped_migration_32/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_version_downloads_version_id ON version_downloads (version_id); \ No newline at end of file diff --git a/migrations/20140929103761_dumped_migration_33/down.sql b/migrations/20140929103761_dumped_migration_33/down.sql new file mode 100644 index 00000000000..16694ca7152 --- /dev/null +++ b/migrations/20140929103761_dumped_migration_33/down.sql @@ -0,0 +1 @@ +DROP INDEX index_version_downloads_date; \ No newline at end of file diff --git a/migrations/20140929103761_dumped_migration_33/up.sql b/migrations/20140929103761_dumped_migration_33/up.sql new file mode 100644 index 00000000000..30fe20569b4 --- /dev/null +++ b/migrations/20140929103761_dumped_migration_33/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_version_downloads_date ON version_downloads (date(date)); \ No newline at end of file diff --git a/migrations/20140929103763_dumped_migration_34/down.sql b/migrations/20140929103763_dumped_migration_34/down.sql new file mode 100644 index 00000000000..eef83198599 --- /dev/null +++ b/migrations/20140929103763_dumped_migration_34/down.sql @@ -0,0 +1 @@ +DROP INDEX index_version_downloads_processed; \ No newline at end of file diff --git a/migrations/20140929103763_dumped_migration_34/up.sql b/migrations/20140929103763_dumped_migration_34/up.sql new file mode 100644 index 00000000000..b330ad41267 --- /dev/null +++ b/migrations/20140929103763_dumped_migration_34/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX index_version_downloads_processed ON version_downloads (processed) + WHERE processed = FALSE; \ No newline at end of file diff --git a/migrations/20140929185718_dumped_migration_35/down.sql b/migrations/20140929185718_dumped_migration_35/down.sql new file mode 100644 index 00000000000..9a65b7d2439 --- /dev/null +++ b/migrations/20140929185718_dumped_migration_35/down.sql @@ -0,0 +1 @@ +DROP INDEX index_crates_name_search; \ No newline at end of file diff --git a/migrations/20140929185718_dumped_migration_35/up.sql b/migrations/20140929185718_dumped_migration_35/up.sql new file mode 100644 index 00000000000..e2155a8a4bc --- /dev/null +++ b/migrations/20140929185718_dumped_migration_35/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_crates_name_search ON crates USING gin(to_tsvector('english', name)); \ No newline at end of file diff --git a/migrations/20140930082104_dumped_migration_36/down.sql b/migrations/20140930082104_dumped_migration_36/down.sql new file mode 100644 index 00000000000..1a6d81bb0c9 --- /dev/null +++ b/migrations/20140930082104_dumped_migration_36/down.sql @@ -0,0 +1,3 @@ +CREATE TABLE version_dependencies ( + version_id INTEGER + ); \ No newline at end of file diff --git a/migrations/20140930082104_dumped_migration_36/up.sql b/migrations/20140930082104_dumped_migration_36/up.sql new file mode 100644 index 00000000000..44bb6f74770 --- /dev/null +++ b/migrations/20140930082104_dumped_migration_36/up.sql @@ -0,0 +1 @@ +DROP TABLE version_dependencies; \ No newline at end of file diff --git a/migrations/20140930082105_dumped_migration_37/down.sql b/migrations/20140930082105_dumped_migration_37/down.sql new file mode 100644 index 00000000000..115bd50be84 --- /dev/null +++ b/migrations/20140930082105_dumped_migration_37/down.sql @@ -0,0 +1 @@ +DROP TABLE dependencies; \ No newline at end of file diff --git a/migrations/20140930082105_dumped_migration_37/up.sql b/migrations/20140930082105_dumped_migration_37/up.sql new file mode 100644 index 00000000000..571cc52acfa --- /dev/null +++ b/migrations/20140930082105_dumped_migration_37/up.sql @@ -0,0 +1,9 @@ +CREATE TABLE dependencies ( + id SERIAL PRIMARY KEY, + version_id INTEGER NOT NULL, + crate_id INTEGER NOT NULL, + req VARCHAR NOT NULL, + optional BOOLEAN NOT NULL, + default_features BOOLEAN NOT NULL, + features VARCHAR NOT NULL + ); \ No newline at end of file diff --git a/migrations/20140930085441_dumped_migration_38/down.sql b/migrations/20140930085441_dumped_migration_38/down.sql new file mode 100644 index 00000000000..39c8b6d726a --- /dev/null +++ b/migrations/20140930085441_dumped_migration_38/down.sql @@ -0,0 +1 @@ +ALTER TABLE versions DROP COLUMN features; \ No newline at end of file diff --git a/migrations/20140930085441_dumped_migration_38/up.sql b/migrations/20140930085441_dumped_migration_38/up.sql new file mode 100644 index 00000000000..cd0eab5fa63 --- /dev/null +++ b/migrations/20140930085441_dumped_migration_38/up.sql @@ -0,0 +1 @@ +ALTER TABLE versions ADD COLUMN features VARCHAR; \ No newline at end of file diff --git a/migrations/20140930203145_dumped_migration_39/down.sql b/migrations/20140930203145_dumped_migration_39/down.sql new file mode 100644 index 00000000000..6e4d051ff59 --- /dev/null +++ b/migrations/20140930203145_dumped_migration_39/down.sql @@ -0,0 +1 @@ +DROP INDEX index_dependencies_version_id; \ No newline at end of file diff --git a/migrations/20140930203145_dumped_migration_39/up.sql b/migrations/20140930203145_dumped_migration_39/up.sql new file mode 100644 index 00000000000..88d02e3f3a8 --- /dev/null +++ b/migrations/20140930203145_dumped_migration_39/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_dependencies_version_id ON dependencies (version_id); \ No newline at end of file diff --git a/migrations/20140930203146_dumped_migration_40/down.sql b/migrations/20140930203146_dumped_migration_40/down.sql new file mode 100644 index 00000000000..6979794178c --- /dev/null +++ b/migrations/20140930203146_dumped_migration_40/down.sql @@ -0,0 +1 @@ +DROP INDEX index_dependencies_crate_id; \ No newline at end of file diff --git a/migrations/20140930203146_dumped_migration_40/up.sql b/migrations/20140930203146_dumped_migration_40/up.sql new file mode 100644 index 00000000000..ebfa6c07db1 --- /dev/null +++ b/migrations/20140930203146_dumped_migration_40/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_dependencies_crate_id ON dependencies (crate_id); \ No newline at end of file diff --git a/migrations/20141001190227_dumped_migration_41/down.sql b/migrations/20141001190227_dumped_migration_41/down.sql new file mode 100644 index 00000000000..bef0321d110 --- /dev/null +++ b/migrations/20141001190227_dumped_migration_41/down.sql @@ -0,0 +1 @@ +ALTER TABLE users DROP COLUMN gh_login; \ No newline at end of file diff --git a/migrations/20141001190227_dumped_migration_41/up.sql b/migrations/20141001190227_dumped_migration_41/up.sql new file mode 100644 index 00000000000..849d747f617 --- /dev/null +++ b/migrations/20141001190227_dumped_migration_41/up.sql @@ -0,0 +1 @@ +ALTER TABLE users ADD COLUMN gh_login VARCHAR NOT NULL; \ No newline at end of file diff --git a/migrations/20141001190228_dumped_migration_42/down.sql b/migrations/20141001190228_dumped_migration_42/down.sql new file mode 100644 index 00000000000..e44cbb569ad --- /dev/null +++ b/migrations/20141001190228_dumped_migration_42/down.sql @@ -0,0 +1 @@ +ALTER TABLE users DROP COLUMN name; \ No newline at end of file diff --git a/migrations/20141001190228_dumped_migration_42/up.sql b/migrations/20141001190228_dumped_migration_42/up.sql new file mode 100644 index 00000000000..d66bae3c0a0 --- /dev/null +++ b/migrations/20141001190228_dumped_migration_42/up.sql @@ -0,0 +1 @@ +ALTER TABLE users ADD COLUMN name VARCHAR; \ No newline at end of file diff --git a/migrations/20141001190229_dumped_migration_43/down.sql b/migrations/20141001190229_dumped_migration_43/down.sql new file mode 100644 index 00000000000..bbd876984fa --- /dev/null +++ b/migrations/20141001190229_dumped_migration_43/down.sql @@ -0,0 +1 @@ +DROP INDEX index_users_gh_login; \ No newline at end of file diff --git a/migrations/20141001190229_dumped_migration_43/up.sql b/migrations/20141001190229_dumped_migration_43/up.sql new file mode 100644 index 00000000000..b358279b29d --- /dev/null +++ b/migrations/20141001190229_dumped_migration_43/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_users_gh_login ON users (gh_login); \ No newline at end of file diff --git a/migrations/20141001190230_dumped_migration_44/down.sql b/migrations/20141001190230_dumped_migration_44/down.sql new file mode 100644 index 00000000000..59b74f050f1 --- /dev/null +++ b/migrations/20141001190230_dumped_migration_44/down.sql @@ -0,0 +1 @@ +ALTER TABLE users ALTER COLUMN email SET NOT NULL; \ No newline at end of file diff --git a/migrations/20141001190230_dumped_migration_44/up.sql b/migrations/20141001190230_dumped_migration_44/up.sql new file mode 100644 index 00000000000..37e402fb30b --- /dev/null +++ b/migrations/20141001190230_dumped_migration_44/up.sql @@ -0,0 +1 @@ +ALTER TABLE users ALTER COLUMN email DROP NOT NULL; \ No newline at end of file diff --git a/migrations/20141001190231_dumped_migration_45/down.sql b/migrations/20141001190231_dumped_migration_45/down.sql new file mode 100644 index 00000000000..08eb43c5b5a --- /dev/null +++ b/migrations/20141001190231_dumped_migration_45/down.sql @@ -0,0 +1 @@ +ALTER TABLE users DROP COLUMN gh_avatar; \ No newline at end of file diff --git a/migrations/20141001190231_dumped_migration_45/up.sql b/migrations/20141001190231_dumped_migration_45/up.sql new file mode 100644 index 00000000000..00bd1a861c4 --- /dev/null +++ b/migrations/20141001190231_dumped_migration_45/up.sql @@ -0,0 +1 @@ +ALTER TABLE users ADD COLUMN gh_avatar VARCHAR; \ No newline at end of file diff --git a/migrations/20141002195939_dumped_migration_46/down.sql b/migrations/20141002195939_dumped_migration_46/down.sql new file mode 100644 index 00000000000..10ed5f50c02 --- /dev/null +++ b/migrations/20141002195939_dumped_migration_46/down.sql @@ -0,0 +1 @@ +DROP INDEX index_crates_user_id; \ No newline at end of file diff --git a/migrations/20141002195939_dumped_migration_46/up.sql b/migrations/20141002195939_dumped_migration_46/up.sql new file mode 100644 index 00000000000..7ea97171b1a --- /dev/null +++ b/migrations/20141002195939_dumped_migration_46/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_crates_user_id ON crates (user_id); \ No newline at end of file diff --git a/migrations/20141002195940_dumped_migration_47/down.sql b/migrations/20141002195940_dumped_migration_47/down.sql new file mode 100644 index 00000000000..2289d7c2a45 --- /dev/null +++ b/migrations/20141002195940_dumped_migration_47/down.sql @@ -0,0 +1 @@ +DROP TABLE follows; \ No newline at end of file diff --git a/migrations/20141002195940_dumped_migration_47/up.sql b/migrations/20141002195940_dumped_migration_47/up.sql new file mode 100644 index 00000000000..b441c3331e5 --- /dev/null +++ b/migrations/20141002195940_dumped_migration_47/up.sql @@ -0,0 +1,4 @@ +CREATE TABLE follows ( + user_id INTEGER NOT NULL, + crate_id INTEGER NOT NULL + ); \ No newline at end of file diff --git a/migrations/20141002195941_dumped_migration_48/down.sql b/migrations/20141002195941_dumped_migration_48/down.sql new file mode 100644 index 00000000000..37fffbb9fd9 --- /dev/null +++ b/migrations/20141002195941_dumped_migration_48/down.sql @@ -0,0 +1 @@ +DROP INDEX index_follows_user_id; \ No newline at end of file diff --git a/migrations/20141002195941_dumped_migration_48/up.sql b/migrations/20141002195941_dumped_migration_48/up.sql new file mode 100644 index 00000000000..c8e80d5f9e6 --- /dev/null +++ b/migrations/20141002195941_dumped_migration_48/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_follows_user_id ON follows (user_id); \ No newline at end of file diff --git a/migrations/20141002222426_dumped_migration_49/down.sql b/migrations/20141002222426_dumped_migration_49/down.sql new file mode 100644 index 00000000000..6da3b2bd92b --- /dev/null +++ b/migrations/20141002222426_dumped_migration_49/down.sql @@ -0,0 +1 @@ +ALTER TABLE crate_downloads DROP CONSTRAINT fk_crate_downloads_crate_id; \ No newline at end of file diff --git a/migrations/20141002222426_dumped_migration_49/up.sql b/migrations/20141002222426_dumped_migration_49/up.sql new file mode 100644 index 00000000000..be4c1470943 --- /dev/null +++ b/migrations/20141002222426_dumped_migration_49/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE crate_downloads ADD CONSTRAINT fk_crate_downloads_crate_id + FOREIGN KEY (crate_id) REFERENCES crates (id); \ No newline at end of file diff --git a/migrations/20141002222427_dumped_migration_50/down.sql b/migrations/20141002222427_dumped_migration_50/down.sql new file mode 100644 index 00000000000..01dff878167 --- /dev/null +++ b/migrations/20141002222427_dumped_migration_50/down.sql @@ -0,0 +1 @@ +ALTER TABLE crates DROP CONSTRAINT fk_crates_user_id; \ No newline at end of file diff --git a/migrations/20141002222427_dumped_migration_50/up.sql b/migrations/20141002222427_dumped_migration_50/up.sql new file mode 100644 index 00000000000..4222e33d310 --- /dev/null +++ b/migrations/20141002222427_dumped_migration_50/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE crates ADD CONSTRAINT fk_crates_user_id + FOREIGN KEY (user_id) REFERENCES users (id); \ No newline at end of file diff --git a/migrations/20141002222428_dumped_migration_51/down.sql b/migrations/20141002222428_dumped_migration_51/down.sql new file mode 100644 index 00000000000..712a31d78a1 --- /dev/null +++ b/migrations/20141002222428_dumped_migration_51/down.sql @@ -0,0 +1 @@ +ALTER TABLE dependencies DROP CONSTRAINT fk_dependencies_version_id; \ No newline at end of file diff --git a/migrations/20141002222428_dumped_migration_51/up.sql b/migrations/20141002222428_dumped_migration_51/up.sql new file mode 100644 index 00000000000..e17bc788bf3 --- /dev/null +++ b/migrations/20141002222428_dumped_migration_51/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE dependencies ADD CONSTRAINT fk_dependencies_version_id + FOREIGN KEY (version_id) REFERENCES versions (id); \ No newline at end of file diff --git a/migrations/20141002222429_dumped_migration_52/down.sql b/migrations/20141002222429_dumped_migration_52/down.sql new file mode 100644 index 00000000000..8b295d2d03c --- /dev/null +++ b/migrations/20141002222429_dumped_migration_52/down.sql @@ -0,0 +1 @@ +ALTER TABLE dependencies DROP CONSTRAINT fk_dependencies_crate_id; \ No newline at end of file diff --git a/migrations/20141002222429_dumped_migration_52/up.sql b/migrations/20141002222429_dumped_migration_52/up.sql new file mode 100644 index 00000000000..1c05c97b7e4 --- /dev/null +++ b/migrations/20141002222429_dumped_migration_52/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE dependencies ADD CONSTRAINT fk_dependencies_crate_id + FOREIGN KEY (crate_id) REFERENCES crates (id); \ No newline at end of file diff --git a/migrations/20141002222430_dumped_migration_53/down.sql b/migrations/20141002222430_dumped_migration_53/down.sql new file mode 100644 index 00000000000..9ad2ba723b6 --- /dev/null +++ b/migrations/20141002222430_dumped_migration_53/down.sql @@ -0,0 +1 @@ +ALTER TABLE follows DROP CONSTRAINT fk_follows_crate_id; \ No newline at end of file diff --git a/migrations/20141002222430_dumped_migration_53/up.sql b/migrations/20141002222430_dumped_migration_53/up.sql new file mode 100644 index 00000000000..e657475c646 --- /dev/null +++ b/migrations/20141002222430_dumped_migration_53/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE follows ADD CONSTRAINT fk_follows_crate_id + FOREIGN KEY (crate_id) REFERENCES crates (id); \ No newline at end of file diff --git a/migrations/20141002222431_dumped_migration_54/down.sql b/migrations/20141002222431_dumped_migration_54/down.sql new file mode 100644 index 00000000000..4951acd0ecc --- /dev/null +++ b/migrations/20141002222431_dumped_migration_54/down.sql @@ -0,0 +1 @@ +ALTER TABLE version_downloads DROP CONSTRAINT fk_version_downloads_version_id; \ No newline at end of file diff --git a/migrations/20141002222431_dumped_migration_54/up.sql b/migrations/20141002222431_dumped_migration_54/up.sql new file mode 100644 index 00000000000..77cb88a395a --- /dev/null +++ b/migrations/20141002222431_dumped_migration_54/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE version_downloads ADD CONSTRAINT fk_version_downloads_version_id + FOREIGN KEY (version_id) REFERENCES versions (id); \ No newline at end of file diff --git a/migrations/20141002222432_dumped_migration_55/down.sql b/migrations/20141002222432_dumped_migration_55/down.sql new file mode 100644 index 00000000000..cc9dd705c0f --- /dev/null +++ b/migrations/20141002222432_dumped_migration_55/down.sql @@ -0,0 +1 @@ +ALTER TABLE versions DROP CONSTRAINT fk_versions_crate_id; \ No newline at end of file diff --git a/migrations/20141002222432_dumped_migration_55/up.sql b/migrations/20141002222432_dumped_migration_55/up.sql new file mode 100644 index 00000000000..a4942de5c77 --- /dev/null +++ b/migrations/20141002222432_dumped_migration_55/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE versions ADD CONSTRAINT fk_versions_crate_id + FOREIGN KEY (crate_id) REFERENCES crates (id); \ No newline at end of file diff --git a/migrations/20141002222433_dumped_migration_56/down.sql b/migrations/20141002222433_dumped_migration_56/down.sql new file mode 100644 index 00000000000..1ef019e3fc6 --- /dev/null +++ b/migrations/20141002222433_dumped_migration_56/down.sql @@ -0,0 +1 @@ +ALTER TABLE follows DROP CONSTRAINT fk_follows_user_id; \ No newline at end of file diff --git a/migrations/20141002222433_dumped_migration_56/up.sql b/migrations/20141002222433_dumped_migration_56/up.sql new file mode 100644 index 00000000000..b6ba7567ff1 --- /dev/null +++ b/migrations/20141002222433_dumped_migration_56/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE follows ADD CONSTRAINT fk_follows_user_id + FOREIGN KEY (user_id) REFERENCES users (id); \ No newline at end of file diff --git a/migrations/20141007131146_dumped_migration_57/down.sql b/migrations/20141007131146_dumped_migration_57/down.sql new file mode 100644 index 00000000000..23548d7c357 --- /dev/null +++ b/migrations/20141007131146_dumped_migration_57/down.sql @@ -0,0 +1 @@ +DROP TABLE version_authors; \ No newline at end of file diff --git a/migrations/20141007131146_dumped_migration_57/up.sql b/migrations/20141007131146_dumped_migration_57/up.sql new file mode 100644 index 00000000000..e86520c4182 --- /dev/null +++ b/migrations/20141007131146_dumped_migration_57/up.sql @@ -0,0 +1,6 @@ +CREATE TABLE version_authors ( + id SERIAL PRIMARY KEY, + version_id INTEGER NOT NULL, + user_id INTEGER, + name VARCHAR NOT NULL + ); \ No newline at end of file diff --git a/migrations/20141007131147_dumped_migration_58/down.sql b/migrations/20141007131147_dumped_migration_58/down.sql new file mode 100644 index 00000000000..7141f7c6dea --- /dev/null +++ b/migrations/20141007131147_dumped_migration_58/down.sql @@ -0,0 +1 @@ +ALTER TABLE version_authors DROP CONSTRAINT fk_version_authors_user_id; \ No newline at end of file diff --git a/migrations/20141007131147_dumped_migration_58/up.sql b/migrations/20141007131147_dumped_migration_58/up.sql new file mode 100644 index 00000000000..73d251ec16e --- /dev/null +++ b/migrations/20141007131147_dumped_migration_58/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE version_authors ADD CONSTRAINT fk_version_authors_user_id + FOREIGN KEY (user_id) REFERENCES users (id); \ No newline at end of file diff --git a/migrations/20141007131148_dumped_migration_59/down.sql b/migrations/20141007131148_dumped_migration_59/down.sql new file mode 100644 index 00000000000..96ce5ff7b47 --- /dev/null +++ b/migrations/20141007131148_dumped_migration_59/down.sql @@ -0,0 +1 @@ +ALTER TABLE version_authors DROP CONSTRAINT fk_version_authors_version_id; \ No newline at end of file diff --git a/migrations/20141007131148_dumped_migration_59/up.sql b/migrations/20141007131148_dumped_migration_59/up.sql new file mode 100644 index 00000000000..094fe883493 --- /dev/null +++ b/migrations/20141007131148_dumped_migration_59/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE version_authors ADD CONSTRAINT fk_version_authors_version_id + FOREIGN KEY (version_id) REFERENCES versions (id); \ No newline at end of file diff --git a/migrations/20141007131149_dumped_migration_60/down.sql b/migrations/20141007131149_dumped_migration_60/down.sql new file mode 100644 index 00000000000..35d3783bd3c --- /dev/null +++ b/migrations/20141007131149_dumped_migration_60/down.sql @@ -0,0 +1 @@ +DROP INDEX index_version_authors_version_id; \ No newline at end of file diff --git a/migrations/20141007131149_dumped_migration_60/up.sql b/migrations/20141007131149_dumped_migration_60/up.sql new file mode 100644 index 00000000000..62d51064571 --- /dev/null +++ b/migrations/20141007131149_dumped_migration_60/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX index_version_authors_version_id + ON version_authors (version_id); \ No newline at end of file diff --git a/migrations/20141007131735_dumped_migration_61/down.sql b/migrations/20141007131735_dumped_migration_61/down.sql new file mode 100644 index 00000000000..c37c0d72649 --- /dev/null +++ b/migrations/20141007131735_dumped_migration_61/down.sql @@ -0,0 +1 @@ +DROP TABLE crate_owners; \ No newline at end of file diff --git a/migrations/20141007131735_dumped_migration_61/up.sql b/migrations/20141007131735_dumped_migration_61/up.sql new file mode 100644 index 00000000000..bb65980d5c0 --- /dev/null +++ b/migrations/20141007131735_dumped_migration_61/up.sql @@ -0,0 +1,7 @@ +CREATE TABLE crate_owners ( + id SERIAL PRIMARY KEY, + crate_id INTEGER NOT NULL, + user_id INTEGER NOT NULL, + created_at TIMESTAMP NOT NULL, + created_by INTEGER + ); \ No newline at end of file diff --git a/migrations/20141007131736_dumped_migration_62/down.sql b/migrations/20141007131736_dumped_migration_62/down.sql new file mode 100644 index 00000000000..bffe0b6a032 --- /dev/null +++ b/migrations/20141007131736_dumped_migration_62/down.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners DROP CONSTRAINT fk_crate_owners_user_id; \ No newline at end of file diff --git a/migrations/20141007131736_dumped_migration_62/up.sql b/migrations/20141007131736_dumped_migration_62/up.sql new file mode 100644 index 00000000000..a95cfe51417 --- /dev/null +++ b/migrations/20141007131736_dumped_migration_62/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE crate_owners ADD CONSTRAINT fk_crate_owners_user_id + FOREIGN KEY (user_id) REFERENCES users (id); \ No newline at end of file diff --git a/migrations/20141007131737_dumped_migration_63/down.sql b/migrations/20141007131737_dumped_migration_63/down.sql new file mode 100644 index 00000000000..aa5e051d77b --- /dev/null +++ b/migrations/20141007131737_dumped_migration_63/down.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners DROP CONSTRAINT fk_crate_owners_created_by; \ No newline at end of file diff --git a/migrations/20141007131737_dumped_migration_63/up.sql b/migrations/20141007131737_dumped_migration_63/up.sql new file mode 100644 index 00000000000..e3c3e32341c --- /dev/null +++ b/migrations/20141007131737_dumped_migration_63/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE crate_owners ADD CONSTRAINT fk_crate_owners_created_by + FOREIGN KEY (created_by) REFERENCES users (id); \ No newline at end of file diff --git a/migrations/20141007131738_dumped_migration_64/down.sql b/migrations/20141007131738_dumped_migration_64/down.sql new file mode 100644 index 00000000000..6b8de2a66c7 --- /dev/null +++ b/migrations/20141007131738_dumped_migration_64/down.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners DROP CONSTRAINT fk_crate_owners_crate_id; \ No newline at end of file diff --git a/migrations/20141007131738_dumped_migration_64/up.sql b/migrations/20141007131738_dumped_migration_64/up.sql new file mode 100644 index 00000000000..d30d96a0047 --- /dev/null +++ b/migrations/20141007131738_dumped_migration_64/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE crate_owners ADD CONSTRAINT fk_crate_owners_crate_id + FOREIGN KEY (crate_id) REFERENCES crates (id); \ No newline at end of file diff --git a/migrations/20141007131739_dumped_migration_65/down.sql b/migrations/20141007131739_dumped_migration_65/down.sql new file mode 100644 index 00000000000..c1038d5e641 --- /dev/null +++ b/migrations/20141007131739_dumped_migration_65/down.sql @@ -0,0 +1 @@ +DROP INDEX index_crate_owners_crate_id; \ No newline at end of file diff --git a/migrations/20141007131739_dumped_migration_65/up.sql b/migrations/20141007131739_dumped_migration_65/up.sql new file mode 100644 index 00000000000..e0c2bfd381c --- /dev/null +++ b/migrations/20141007131739_dumped_migration_65/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX index_crate_owners_crate_id + ON crate_owners (crate_id); \ No newline at end of file diff --git a/migrations/20141007131740_dumped_migration_66/down.sql b/migrations/20141007131740_dumped_migration_66/down.sql new file mode 100644 index 00000000000..4e8bbf9c4ca --- /dev/null +++ b/migrations/20141007131740_dumped_migration_66/down.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners DROP COLUMN deleted; \ No newline at end of file diff --git a/migrations/20141007131740_dumped_migration_66/up.sql b/migrations/20141007131740_dumped_migration_66/up.sql new file mode 100644 index 00000000000..28b0ece7050 --- /dev/null +++ b/migrations/20141007131740_dumped_migration_66/up.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners ADD COLUMN deleted BOOLEAN NOT NULL; \ No newline at end of file diff --git a/migrations/20141007131741_dumped_migration_67/down.sql b/migrations/20141007131741_dumped_migration_67/down.sql new file mode 100644 index 00000000000..a05f9ccb272 --- /dev/null +++ b/migrations/20141007131741_dumped_migration_67/down.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners DROP COLUMN updated_at; \ No newline at end of file diff --git a/migrations/20141007131741_dumped_migration_67/up.sql b/migrations/20141007131741_dumped_migration_67/up.sql new file mode 100644 index 00000000000..fbfbf6c5d43 --- /dev/null +++ b/migrations/20141007131741_dumped_migration_67/up.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners ADD COLUMN updated_at TIMESTAMP NOT NULL; \ No newline at end of file diff --git a/migrations/20141007171515_dumped_migration_68/down.sql b/migrations/20141007171515_dumped_migration_68/down.sql new file mode 100644 index 00000000000..584fae85824 --- /dev/null +++ b/migrations/20141007171515_dumped_migration_68/down.sql @@ -0,0 +1 @@ +ALTER TABLE crates DROP COLUMN description; \ No newline at end of file diff --git a/migrations/20141007171515_dumped_migration_68/up.sql b/migrations/20141007171515_dumped_migration_68/up.sql new file mode 100644 index 00000000000..523774a3fb1 --- /dev/null +++ b/migrations/20141007171515_dumped_migration_68/up.sql @@ -0,0 +1 @@ +ALTER TABLE crates ADD COLUMN description VARCHAR; \ No newline at end of file diff --git a/migrations/20141007171516_dumped_migration_69/down.sql b/migrations/20141007171516_dumped_migration_69/down.sql new file mode 100644 index 00000000000..e094cb1e01c --- /dev/null +++ b/migrations/20141007171516_dumped_migration_69/down.sql @@ -0,0 +1 @@ +ALTER TABLE crates DROP COLUMN homepage; \ No newline at end of file diff --git a/migrations/20141007171516_dumped_migration_69/up.sql b/migrations/20141007171516_dumped_migration_69/up.sql new file mode 100644 index 00000000000..0bcd032e55d --- /dev/null +++ b/migrations/20141007171516_dumped_migration_69/up.sql @@ -0,0 +1 @@ +ALTER TABLE crates ADD COLUMN homepage VARCHAR; \ No newline at end of file diff --git a/migrations/20141007171517_dumped_migration_70/down.sql b/migrations/20141007171517_dumped_migration_70/down.sql new file mode 100644 index 00000000000..0953597d2d8 --- /dev/null +++ b/migrations/20141007171517_dumped_migration_70/down.sql @@ -0,0 +1 @@ +ALTER TABLE crates DROP COLUMN documentation; \ No newline at end of file diff --git a/migrations/20141007171517_dumped_migration_70/up.sql b/migrations/20141007171517_dumped_migration_70/up.sql new file mode 100644 index 00000000000..32e16ea4adc --- /dev/null +++ b/migrations/20141007171517_dumped_migration_70/up.sql @@ -0,0 +1 @@ +ALTER TABLE crates ADD COLUMN documentation VARCHAR; \ No newline at end of file diff --git a/migrations/20141010150327_dumped_migration_71/down.sql b/migrations/20141010150327_dumped_migration_71/down.sql new file mode 100644 index 00000000000..b4ae8216c1f --- /dev/null +++ b/migrations/20141010150327_dumped_migration_71/down.sql @@ -0,0 +1 @@ +ALTER TABLE crates DROP COLUMN readme; \ No newline at end of file diff --git a/migrations/20141010150327_dumped_migration_71/up.sql b/migrations/20141010150327_dumped_migration_71/up.sql new file mode 100644 index 00000000000..54c9cfb6eb8 --- /dev/null +++ b/migrations/20141010150327_dumped_migration_71/up.sql @@ -0,0 +1 @@ +ALTER TABLE crates ADD COLUMN readme VARCHAR; \ No newline at end of file diff --git a/migrations/20141013115510_dumped_migration_72/down.sql b/migrations/20141013115510_dumped_migration_72/down.sql new file mode 100644 index 00000000000..cac20d6de88 --- /dev/null +++ b/migrations/20141013115510_dumped_migration_72/down.sql @@ -0,0 +1 @@ +ALTER TABLE versions DROP COLUMN yanked; \ No newline at end of file diff --git a/migrations/20141013115510_dumped_migration_72/up.sql b/migrations/20141013115510_dumped_migration_72/up.sql new file mode 100644 index 00000000000..5bbdc3f2b97 --- /dev/null +++ b/migrations/20141013115510_dumped_migration_72/up.sql @@ -0,0 +1 @@ +ALTER TABLE versions ADD COLUMN yanked BOOLEAN DEFAULT FALSE; \ No newline at end of file diff --git a/migrations/20141020175647_dumped_migration_73/down.sql b/migrations/20141020175647_dumped_migration_73/down.sql new file mode 100644 index 00000000000..c66882893df --- /dev/null +++ b/migrations/20141020175647_dumped_migration_73/down.sql @@ -0,0 +1 @@ +ALTER TABLE crates DROP COLUMN textsearchable_index_col; \ No newline at end of file diff --git a/migrations/20141020175647_dumped_migration_73/up.sql b/migrations/20141020175647_dumped_migration_73/up.sql new file mode 100644 index 00000000000..bd9907059ff --- /dev/null +++ b/migrations/20141020175647_dumped_migration_73/up.sql @@ -0,0 +1 @@ +ALTER TABLE crates ADD COLUMN textsearchable_index_col tsvector; \ No newline at end of file diff --git a/migrations/20141020175648_dumped_migration_74/down.sql b/migrations/20141020175648_dumped_migration_74/down.sql new file mode 100644 index 00000000000..e2155a8a4bc --- /dev/null +++ b/migrations/20141020175648_dumped_migration_74/down.sql @@ -0,0 +1 @@ +CREATE INDEX index_crates_name_search ON crates USING gin(to_tsvector('english', name)); \ No newline at end of file diff --git a/migrations/20141020175648_dumped_migration_74/up.sql b/migrations/20141020175648_dumped_migration_74/up.sql new file mode 100644 index 00000000000..9a65b7d2439 --- /dev/null +++ b/migrations/20141020175648_dumped_migration_74/up.sql @@ -0,0 +1 @@ +DROP INDEX index_crates_name_search; \ No newline at end of file diff --git a/migrations/20141020175649_dumped_migration_75/down.sql b/migrations/20141020175649_dumped_migration_75/down.sql new file mode 100644 index 00000000000..9a65b7d2439 --- /dev/null +++ b/migrations/20141020175649_dumped_migration_75/down.sql @@ -0,0 +1 @@ +DROP INDEX index_crates_name_search; \ No newline at end of file diff --git a/migrations/20141020175649_dumped_migration_75/up.sql b/migrations/20141020175649_dumped_migration_75/up.sql new file mode 100644 index 00000000000..77e64b77bb3 --- /dev/null +++ b/migrations/20141020175649_dumped_migration_75/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_crates_name_search ON crates USING gin(textsearchable_index_col); \ No newline at end of file diff --git a/migrations/20141020175650_dumped_migration_76/down.sql b/migrations/20141020175650_dumped_migration_76/down.sql new file mode 100644 index 00000000000..7f1e7204905 --- /dev/null +++ b/migrations/20141020175650_dumped_migration_76/down.sql @@ -0,0 +1,3 @@ +DROP TRIGGER trigger_crates_tsvector_update + ON crates; +DROP FUNCTION trigger_crates_name_search(); \ No newline at end of file diff --git a/migrations/20141020175650_dumped_migration_76/up.sql b/migrations/20141020175650_dumped_migration_76/up.sql new file mode 100644 index 00000000000..8c03e891961 --- /dev/null +++ b/migrations/20141020175650_dumped_migration_76/up.sql @@ -0,0 +1,18 @@ +CREATE FUNCTION trigger_crates_name_search() RETURNS trigger AS $$ + begin + new.textsearchable_index_col := + setweight(to_tsvector('pg_catalog.english', + coalesce(new.name, '')), 'A') || + setweight(to_tsvector('pg_catalog.english', + coalesce(new.keywords, '')), 'B') || + setweight(to_tsvector('pg_catalog.english', + coalesce(new.description, '')), 'C') || + setweight(to_tsvector('pg_catalog.english', + coalesce(new.readme, '')), 'D'); + return new; + end + $$ LANGUAGE plpgsql; + + CREATE TRIGGER trigger_crates_tsvector_update BEFORE INSERT OR UPDATE + ON crates + FOR EACH ROW EXECUTE PROCEDURE trigger_crates_name_search(); \ No newline at end of file diff --git a/migrations/20141020175651_dumped_migration_77/down.sql b/migrations/20141020175651_dumped_migration_77/down.sql new file mode 100644 index 00000000000..d5f844a0831 --- /dev/null +++ b/migrations/20141020175651_dumped_migration_77/down.sql @@ -0,0 +1 @@ +ALTER TABLE crates DROP COLUMN keywords; \ No newline at end of file diff --git a/migrations/20141020175651_dumped_migration_77/up.sql b/migrations/20141020175651_dumped_migration_77/up.sql new file mode 100644 index 00000000000..b91c52c4c0f --- /dev/null +++ b/migrations/20141020175651_dumped_migration_77/up.sql @@ -0,0 +1 @@ +ALTER TABLE crates ADD COLUMN keywords varchar; \ No newline at end of file diff --git a/migrations/20141021103503_dumped_migration_78/down.sql b/migrations/20141021103503_dumped_migration_78/down.sql new file mode 100644 index 00000000000..c6bd5cfa815 --- /dev/null +++ b/migrations/20141021103503_dumped_migration_78/down.sql @@ -0,0 +1 @@ +DROP TABLE keywords; \ No newline at end of file diff --git a/migrations/20141021103503_dumped_migration_78/up.sql b/migrations/20141021103503_dumped_migration_78/up.sql new file mode 100644 index 00000000000..fba0b49fcc6 --- /dev/null +++ b/migrations/20141021103503_dumped_migration_78/up.sql @@ -0,0 +1,6 @@ +CREATE TABLE keywords ( + id SERIAL PRIMARY KEY, + keyword VARCHAR NOT NULL UNIQUE, + crates_cnt INTEGER NOT NULL, + created_at TIMESTAMP NOT NULL + ); \ No newline at end of file diff --git a/migrations/20141021103504_dumped_migration_79/down.sql b/migrations/20141021103504_dumped_migration_79/down.sql new file mode 100644 index 00000000000..76d2cd14fad --- /dev/null +++ b/migrations/20141021103504_dumped_migration_79/down.sql @@ -0,0 +1 @@ +DROP TABLE crates_keywords; \ No newline at end of file diff --git a/migrations/20141021103504_dumped_migration_79/up.sql b/migrations/20141021103504_dumped_migration_79/up.sql new file mode 100644 index 00000000000..807a49c0a17 --- /dev/null +++ b/migrations/20141021103504_dumped_migration_79/up.sql @@ -0,0 +1,4 @@ +CREATE TABLE crates_keywords ( + crate_id INTEGER NOT NULL, + keyword_id INTEGER NOT NULL + ); \ No newline at end of file diff --git a/migrations/20141021103505_dumped_migration_80/down.sql b/migrations/20141021103505_dumped_migration_80/down.sql new file mode 100644 index 00000000000..cb6c98eecf8 --- /dev/null +++ b/migrations/20141021103505_dumped_migration_80/down.sql @@ -0,0 +1 @@ +ALTER TABLE crates_keywords DROP CONSTRAINT fk_crates_keywords_crate_id; \ No newline at end of file diff --git a/migrations/20141021103505_dumped_migration_80/up.sql b/migrations/20141021103505_dumped_migration_80/up.sql new file mode 100644 index 00000000000..103e22cc67a --- /dev/null +++ b/migrations/20141021103505_dumped_migration_80/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE crates_keywords ADD CONSTRAINT fk_crates_keywords_crate_id + FOREIGN KEY (crate_id) REFERENCES crates (id); \ No newline at end of file diff --git a/migrations/20141021103506_dumped_migration_81/down.sql b/migrations/20141021103506_dumped_migration_81/down.sql new file mode 100644 index 00000000000..a8cd602b575 --- /dev/null +++ b/migrations/20141021103506_dumped_migration_81/down.sql @@ -0,0 +1 @@ +ALTER TABLE crates_keywords DROP CONSTRAINT fk_crates_keywords_keyword_id; \ No newline at end of file diff --git a/migrations/20141021103506_dumped_migration_81/up.sql b/migrations/20141021103506_dumped_migration_81/up.sql new file mode 100644 index 00000000000..5bedc31154f --- /dev/null +++ b/migrations/20141021103506_dumped_migration_81/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE crates_keywords ADD CONSTRAINT fk_crates_keywords_keyword_id + FOREIGN KEY (keyword_id) REFERENCES keywords (id); \ No newline at end of file diff --git a/migrations/20141021103507_dumped_migration_82/down.sql b/migrations/20141021103507_dumped_migration_82/down.sql new file mode 100644 index 00000000000..eca757a6dca --- /dev/null +++ b/migrations/20141021103507_dumped_migration_82/down.sql @@ -0,0 +1 @@ +DROP INDEX index_crates_keywords_crate_id; \ No newline at end of file diff --git a/migrations/20141021103507_dumped_migration_82/up.sql b/migrations/20141021103507_dumped_migration_82/up.sql new file mode 100644 index 00000000000..ceebd23cf61 --- /dev/null +++ b/migrations/20141021103507_dumped_migration_82/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX index_crates_keywords_crate_id + ON crates_keywords (crate_id); \ No newline at end of file diff --git a/migrations/20141021103508_dumped_migration_83/down.sql b/migrations/20141021103508_dumped_migration_83/down.sql new file mode 100644 index 00000000000..31eb2b6d65a --- /dev/null +++ b/migrations/20141021103508_dumped_migration_83/down.sql @@ -0,0 +1 @@ +DROP INDEX index_crates_keywords_keyword_id; \ No newline at end of file diff --git a/migrations/20141021103508_dumped_migration_83/up.sql b/migrations/20141021103508_dumped_migration_83/up.sql new file mode 100644 index 00000000000..88e9d169403 --- /dev/null +++ b/migrations/20141021103508_dumped_migration_83/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX index_crates_keywords_keyword_id + ON crates_keywords (keyword_id); \ No newline at end of file diff --git a/migrations/20141021103509_dumped_migration_84/down.sql b/migrations/20141021103509_dumped_migration_84/down.sql new file mode 100644 index 00000000000..26951a75676 --- /dev/null +++ b/migrations/20141021103509_dumped_migration_84/down.sql @@ -0,0 +1 @@ +DROP INDEX index_keywords_keyword; \ No newline at end of file diff --git a/migrations/20141021103509_dumped_migration_84/up.sql b/migrations/20141021103509_dumped_migration_84/up.sql new file mode 100644 index 00000000000..7bde31319d6 --- /dev/null +++ b/migrations/20141021103509_dumped_migration_84/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX index_keywords_keyword + ON keywords (keyword); \ No newline at end of file diff --git a/migrations/20141021103510_dumped_migration_85/down.sql b/migrations/20141021103510_dumped_migration_85/down.sql new file mode 100644 index 00000000000..d6058b639dd --- /dev/null +++ b/migrations/20141021103510_dumped_migration_85/down.sql @@ -0,0 +1 @@ +DROP INDEX index_keywords_crates_cnt; \ No newline at end of file diff --git a/migrations/20141021103510_dumped_migration_85/up.sql b/migrations/20141021103510_dumped_migration_85/up.sql new file mode 100644 index 00000000000..87c9fa87ea0 --- /dev/null +++ b/migrations/20141021103510_dumped_migration_85/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX index_keywords_crates_cnt + ON keywords (crates_cnt); \ No newline at end of file diff --git a/migrations/20141022110441_dumped_migration_86/down.sql b/migrations/20141022110441_dumped_migration_86/down.sql new file mode 100644 index 00000000000..23aa62add5c --- /dev/null +++ b/migrations/20141022110441_dumped_migration_86/down.sql @@ -0,0 +1 @@ +ALTER TABLE dependencies DROP COLUMN target; \ No newline at end of file diff --git a/migrations/20141022110441_dumped_migration_86/up.sql b/migrations/20141022110441_dumped_migration_86/up.sql new file mode 100644 index 00000000000..40bf27dd7b3 --- /dev/null +++ b/migrations/20141022110441_dumped_migration_86/up.sql @@ -0,0 +1 @@ +ALTER TABLE dependencies ADD COLUMN target varchar; \ No newline at end of file diff --git a/migrations/20141023180230_dumped_migration_87/down.sql b/migrations/20141023180230_dumped_migration_87/down.sql new file mode 100644 index 00000000000..3e02963c331 --- /dev/null +++ b/migrations/20141023180230_dumped_migration_87/down.sql @@ -0,0 +1 @@ +ALTER TABLE crates DROP COLUMN license; \ No newline at end of file diff --git a/migrations/20141023180230_dumped_migration_87/up.sql b/migrations/20141023180230_dumped_migration_87/up.sql new file mode 100644 index 00000000000..259c81eb5d6 --- /dev/null +++ b/migrations/20141023180230_dumped_migration_87/up.sql @@ -0,0 +1 @@ +ALTER TABLE crates ADD COLUMN license varchar; \ No newline at end of file diff --git a/migrations/20141023180231_dumped_migration_88/down.sql b/migrations/20141023180231_dumped_migration_88/down.sql new file mode 100644 index 00000000000..552697861cb --- /dev/null +++ b/migrations/20141023180231_dumped_migration_88/down.sql @@ -0,0 +1 @@ +ALTER TABLE crates DROP COLUMN repository; \ No newline at end of file diff --git a/migrations/20141023180231_dumped_migration_88/up.sql b/migrations/20141023180231_dumped_migration_88/up.sql new file mode 100644 index 00000000000..8c5b1c7c76c --- /dev/null +++ b/migrations/20141023180231_dumped_migration_88/up.sql @@ -0,0 +1 @@ +ALTER TABLE crates ADD COLUMN repository varchar; \ No newline at end of file diff --git a/migrations/20141112082527_dumped_migration_89/down.sql b/migrations/20141112082527_dumped_migration_89/down.sql new file mode 100644 index 00000000000..e69de29bb2d diff --git a/migrations/20141112082527_dumped_migration_89/up.sql b/migrations/20141112082527_dumped_migration_89/up.sql new file mode 100644 index 00000000000..8fe0b06cf2d --- /dev/null +++ b/migrations/20141112082527_dumped_migration_89/up.sql @@ -0,0 +1 @@ +ALTER TABLE users DROP CONSTRAINT IF EXISTS users_email_key; \ No newline at end of file diff --git a/migrations/20141120162357_dumped_migration_90/down.sql b/migrations/20141120162357_dumped_migration_90/down.sql new file mode 100644 index 00000000000..4d9a64a99e1 --- /dev/null +++ b/migrations/20141120162357_dumped_migration_90/down.sql @@ -0,0 +1 @@ +ALTER TABLE dependencies DROP COLUMN kind; \ No newline at end of file diff --git a/migrations/20141120162357_dumped_migration_90/up.sql b/migrations/20141120162357_dumped_migration_90/up.sql new file mode 100644 index 00000000000..e3c8e3b4bf4 --- /dev/null +++ b/migrations/20141120162357_dumped_migration_90/up.sql @@ -0,0 +1 @@ +ALTER TABLE dependencies ADD COLUMN kind INTEGER; \ No newline at end of file diff --git a/migrations/20141121191309_dumped_migration_91/down.sql b/migrations/20141121191309_dumped_migration_91/down.sql new file mode 100644 index 00000000000..de882556fbd --- /dev/null +++ b/migrations/20141121191309_dumped_migration_91/down.sql @@ -0,0 +1,2 @@ +DROP INDEX index_crates_name; +ALTER TABLE crates ADD CONSTRAINT packages_name_key UNIQUE (name); \ No newline at end of file diff --git a/migrations/20141121191309_dumped_migration_91/up.sql b/migrations/20141121191309_dumped_migration_91/up.sql new file mode 100644 index 00000000000..8dd59f1bd9b --- /dev/null +++ b/migrations/20141121191309_dumped_migration_91/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE crates DROP CONSTRAINT packages_name_key; +CREATE UNIQUE INDEX index_crates_name ON crates (lower(name)); \ No newline at end of file diff --git a/migrations/20150209202206_dumped_migration_92/down.sql b/migrations/20150209202206_dumped_migration_92/down.sql new file mode 100644 index 00000000000..b3f17187802 --- /dev/null +++ b/migrations/20150209202206_dumped_migration_92/down.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners DROP CONSTRAINT crate_owners_unique_user_per_crate; \ No newline at end of file diff --git a/migrations/20150209202206_dumped_migration_92/up.sql b/migrations/20150209202206_dumped_migration_92/up.sql new file mode 100644 index 00000000000..504923e5e61 --- /dev/null +++ b/migrations/20150209202206_dumped_migration_92/up.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners ADD CONSTRAINT crate_owners_unique_user_per_crate UNIQUE (user_id, crate_id); \ No newline at end of file diff --git a/migrations/20150319224700_dumped_migration_93/down.sql b/migrations/20150319224700_dumped_migration_93/down.sql new file mode 100644 index 00000000000..7b9b4d7c8ad --- /dev/null +++ b/migrations/20150319224700_dumped_migration_93/down.sql @@ -0,0 +1 @@ +DROP FUNCTION canon_crate_name(text); \ No newline at end of file diff --git a/migrations/20150319224700_dumped_migration_93/up.sql b/migrations/20150319224700_dumped_migration_93/up.sql new file mode 100644 index 00000000000..1cf66c45d83 --- /dev/null +++ b/migrations/20150319224700_dumped_migration_93/up.sql @@ -0,0 +1,4 @@ +CREATE FUNCTION canon_crate_name(text) RETURNS text AS $$ + SELECT replace(lower($1), '-', '_') + $$ LANGUAGE SQL + ; \ No newline at end of file diff --git a/migrations/20150319224701_dumped_migration_94/down.sql b/migrations/20150319224701_dumped_migration_94/down.sql new file mode 100644 index 00000000000..4826063075a --- /dev/null +++ b/migrations/20150319224701_dumped_migration_94/down.sql @@ -0,0 +1,2 @@ +DROP INDEX index_crates_name; +CREATE UNIQUE INDEX index_crates_name ON crates (lower(name)); \ No newline at end of file diff --git a/migrations/20150319224701_dumped_migration_94/up.sql b/migrations/20150319224701_dumped_migration_94/up.sql new file mode 100644 index 00000000000..025f314b49f --- /dev/null +++ b/migrations/20150319224701_dumped_migration_94/up.sql @@ -0,0 +1,2 @@ +DROP INDEX index_crates_name; +CREATE UNIQUE INDEX index_crates_name ON crates (canon_crate_name(name)); \ No newline at end of file diff --git a/migrations/20150320174400_dumped_migration_95/down.sql b/migrations/20150320174400_dumped_migration_95/down.sql new file mode 100644 index 00000000000..b6c50b6fec6 --- /dev/null +++ b/migrations/20150320174400_dumped_migration_95/down.sql @@ -0,0 +1 @@ +DROP INDEX index_keywords_lower_keyword; \ No newline at end of file diff --git a/migrations/20150320174400_dumped_migration_95/up.sql b/migrations/20150320174400_dumped_migration_95/up.sql new file mode 100644 index 00000000000..0bdcbe16b26 --- /dev/null +++ b/migrations/20150320174400_dumped_migration_95/up.sql @@ -0,0 +1 @@ +CREATE INDEX index_keywords_lower_keyword ON keywords (lower(keyword)); \ No newline at end of file diff --git a/migrations/20150715170350_dumped_migration_96/down.sql b/migrations/20150715170350_dumped_migration_96/down.sql new file mode 100644 index 00000000000..bf867cea01c --- /dev/null +++ b/migrations/20150715170350_dumped_migration_96/down.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners DROP COLUMN owner_kind; \ No newline at end of file diff --git a/migrations/20150715170350_dumped_migration_96/up.sql b/migrations/20150715170350_dumped_migration_96/up.sql new file mode 100644 index 00000000000..40341cd34fb --- /dev/null +++ b/migrations/20150715170350_dumped_migration_96/up.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners ADD COLUMN owner_kind INTEGER NOT NULL DEFAULT 0; \ No newline at end of file diff --git a/migrations/20150804170127_dumped_migration_97/down.sql b/migrations/20150804170127_dumped_migration_97/down.sql new file mode 100644 index 00000000000..3048dae05b8 --- /dev/null +++ b/migrations/20150804170127_dumped_migration_97/down.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners ALTER owner_kind SET DEFAULT 0; \ No newline at end of file diff --git a/migrations/20150804170127_dumped_migration_97/up.sql b/migrations/20150804170127_dumped_migration_97/up.sql new file mode 100644 index 00000000000..615e6adc238 --- /dev/null +++ b/migrations/20150804170127_dumped_migration_97/up.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners ALTER owner_kind DROP DEFAULT; \ No newline at end of file diff --git a/migrations/20150804170128_dumped_migration_98/down.sql b/migrations/20150804170128_dumped_migration_98/down.sql new file mode 100644 index 00000000000..237b7e8588b --- /dev/null +++ b/migrations/20150804170128_dumped_migration_98/down.sql @@ -0,0 +1 @@ +DROP TABLE teams; \ No newline at end of file diff --git a/migrations/20150804170128_dumped_migration_98/up.sql b/migrations/20150804170128_dumped_migration_98/up.sql new file mode 100644 index 00000000000..2dfe12d0512 --- /dev/null +++ b/migrations/20150804170128_dumped_migration_98/up.sql @@ -0,0 +1,7 @@ +CREATE TABLE teams ( + id SERIAL PRIMARY KEY, + login VARCHAR NOT NULL UNIQUE, + github_id INTEGER NOT NULL UNIQUE, + name VARCHAR, + avatar VARCHAR + ); \ No newline at end of file diff --git a/migrations/20150804170129_dumped_migration_99/down.sql b/migrations/20150804170129_dumped_migration_99/down.sql new file mode 100644 index 00000000000..27297de5032 --- /dev/null +++ b/migrations/20150804170129_dumped_migration_99/down.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners RENAME owner_id TO user_id; \ No newline at end of file diff --git a/migrations/20150804170129_dumped_migration_99/up.sql b/migrations/20150804170129_dumped_migration_99/up.sql new file mode 100644 index 00000000000..ab49a72c8ed --- /dev/null +++ b/migrations/20150804170129_dumped_migration_99/up.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners RENAME user_id TO owner_id; \ No newline at end of file diff --git a/migrations/20150804170130_dumped_migration_100/down.sql b/migrations/20150804170130_dumped_migration_100/down.sql new file mode 100644 index 00000000000..84218c1aef9 --- /dev/null +++ b/migrations/20150804170130_dumped_migration_100/down.sql @@ -0,0 +1,2 @@ +ALTER TABLE crate_owners ADD CONSTRAINT fk_crate_owners_user_id + FOREIGN KEY (owner_id) REFERENCES users (id); \ No newline at end of file diff --git a/migrations/20150804170130_dumped_migration_100/up.sql b/migrations/20150804170130_dumped_migration_100/up.sql new file mode 100644 index 00000000000..bffe0b6a032 --- /dev/null +++ b/migrations/20150804170130_dumped_migration_100/up.sql @@ -0,0 +1 @@ +ALTER TABLE crate_owners DROP CONSTRAINT fk_crate_owners_user_id; \ No newline at end of file diff --git a/migrations/20150818112907_dumped_migration_101/down.sql b/migrations/20150818112907_dumped_migration_101/down.sql new file mode 100644 index 00000000000..dbf69cf48ac --- /dev/null +++ b/migrations/20150818112907_dumped_migration_101/down.sql @@ -0,0 +1,2 @@ +ALTER TABLE crate_owners DROP CONSTRAINT crate_owners_unique_owner_per_crate; +ALTER TABLE crate_owners ADD CONSTRAINT crate_owners_unique_user_per_crate UNIQUE (owner_id, crate_id); \ No newline at end of file diff --git a/migrations/20150818112907_dumped_migration_101/up.sql b/migrations/20150818112907_dumped_migration_101/up.sql new file mode 100644 index 00000000000..a3835199bfb --- /dev/null +++ b/migrations/20150818112907_dumped_migration_101/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE crate_owners DROP CONSTRAINT crate_owners_unique_user_per_crate; +ALTER TABLE crate_owners ADD CONSTRAINT crate_owners_unique_owner_per_crate UNIQUE (owner_id, crate_id, owner_kind); \ No newline at end of file diff --git a/migrations/20151118135514_dumped_migration_102/down.sql b/migrations/20151118135514_dumped_migration_102/down.sql new file mode 100644 index 00000000000..523929c332f --- /dev/null +++ b/migrations/20151118135514_dumped_migration_102/down.sql @@ -0,0 +1 @@ +ALTER TABLE crates DROP COLUMN max_upload_size; \ No newline at end of file diff --git a/migrations/20151118135514_dumped_migration_102/up.sql b/migrations/20151118135514_dumped_migration_102/up.sql new file mode 100644 index 00000000000..bed2ec3c1d2 --- /dev/null +++ b/migrations/20151118135514_dumped_migration_102/up.sql @@ -0,0 +1 @@ +ALTER TABLE crates ADD COLUMN max_upload_size INTEGER; \ No newline at end of file diff --git a/migrations/20151126095136_dumped_migration_103/down.sql b/migrations/20151126095136_dumped_migration_103/down.sql new file mode 100644 index 00000000000..29f6d8930d0 --- /dev/null +++ b/migrations/20151126095136_dumped_migration_103/down.sql @@ -0,0 +1,29 @@ +ALTER TABLE version_downloads ALTER downloads DROP DEFAULT; + ALTER TABLE version_downloads ALTER counted DROP DEFAULT; + ALTER TABLE version_downloads ALTER date DROP DEFAULT; + ALTER TABLE version_downloads ALTER processed DROP DEFAULT; + + ALTER TABLE keywords ALTER created_at DROP DEFAULT; + ALTER TABLE keywords ALTER crates_cnt DROP DEFAULT; + + ALTER TABLE crates ALTER created_at DROP DEFAULT; + ALTER TABLE crates ALTER updated_at DROP DEFAULT; + ALTER TABLE crates ALTER downloads DROP DEFAULT; + ALTER TABLE crates ALTER max_version DROP DEFAULT; + + ALTER TABLE crate_owners ALTER created_at DROP DEFAULT; + ALTER TABLE crate_owners ALTER updated_at DROP DEFAULT; + ALTER TABLE crate_owners ALTER deleted DROP DEFAULT; + + ALTER TABLE versions ALTER created_at DROP DEFAULT; + ALTER TABLE versions ALTER updated_at DROP DEFAULT; + ALTER TABLE versions ALTER downloads DROP DEFAULT; + + DROP TRIGGER trigger_update_keywords_crates_cnt ON crates_keywords; + DROP FUNCTION update_keywords_crates_cnt(); + + DROP TRIGGER trigger_crate_owners_set_updated_at ON crate_owners; + DROP TRIGGER trigger_crates_set_updated_at ON crates; + DROP TRIGGER trigger_versions_set_updated_at ON versions; + + DROP FUNCTION set_updated_at(); \ No newline at end of file diff --git a/migrations/20151126095136_dumped_migration_103/up.sql b/migrations/20151126095136_dumped_migration_103/up.sql new file mode 100644 index 00000000000..1907b11d442 --- /dev/null +++ b/migrations/20151126095136_dumped_migration_103/up.sql @@ -0,0 +1,57 @@ +ALTER TABLE version_downloads ALTER downloads SET DEFAULT 1; + ALTER TABLE version_downloads ALTER counted SET DEFAULT 0; + ALTER TABLE version_downloads ALTER date SET DEFAULT current_date; + ALTER TABLE version_downloads ALTER processed SET DEFAULT 'f'; + + ALTER TABLE keywords ALTER created_at SET DEFAULT current_timestamp; + ALTER TABLE keywords ALTER crates_cnt SET DEFAULT 0; + + ALTER TABLE crates ALTER created_at SET DEFAULT current_timestamp; + ALTER TABLE crates ALTER updated_at SET DEFAULT current_timestamp; + ALTER TABLE crates ALTER downloads SET DEFAULT 0; + ALTER TABLE crates ALTER max_version SET DEFAULT '0.0.0'; + + ALTER TABLE crate_owners ALTER created_at SET DEFAULT current_timestamp; + ALTER TABLE crate_owners ALTER updated_at SET DEFAULT current_timestamp; + ALTER TABLE crate_owners ALTER deleted SET DEFAULT 'f'; + + ALTER TABLE versions ALTER created_at SET DEFAULT current_timestamp; + ALTER TABLE versions ALTER updated_at SET DEFAULT current_timestamp; + ALTER TABLE versions ALTER downloads SET DEFAULT 0; + + CREATE FUNCTION set_updated_at() RETURNS trigger AS $$ + BEGIN + IF (NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at) THEN + NEW.updated_at := current_timestamp; + END IF; + RETURN NEW; + END + $$ LANGUAGE plpgsql; + + CREATE FUNCTION update_keywords_crates_cnt() RETURNS trigger AS $$ + BEGIN + IF (TG_OP = 'INSERT') THEN + UPDATE keywords SET crates_cnt = crates_cnt + 1 WHERE id = NEW.keyword_id; + return NEW; + ELSIF (TG_OP = 'DELETE') THEN + UPDATE keywords SET crates_cnt = crates_cnt - 1 WHERE id = OLD.keyword_id; + return OLD; + END IF; + END + $$ LANGUAGE plpgsql; + + CREATE TRIGGER trigger_update_keywords_crates_cnt BEFORE INSERT OR DELETE + ON crates_keywords + FOR EACH ROW EXECUTE PROCEDURE update_keywords_crates_cnt(); + + CREATE TRIGGER trigger_crate_owners_set_updated_at BEFORE UPDATE + ON crate_owners + FOR EACH ROW EXECUTE PROCEDURE set_updated_at(); + + CREATE TRIGGER trigger_crates_set_updated_at BEFORE UPDATE + ON crates + FOR EACH ROW EXECUTE PROCEDURE set_updated_at(); + + CREATE TRIGGER trigger_versions_set_updated_at BEFORE UPDATE + ON versions + FOR EACH ROW EXECUTE PROCEDURE set_updated_at(); \ No newline at end of file diff --git a/migrations/20151211122515_dumped_migration_104/down.sql b/migrations/20151211122515_dumped_migration_104/down.sql new file mode 100644 index 00000000000..e974e6cf6d5 --- /dev/null +++ b/migrations/20151211122515_dumped_migration_104/down.sql @@ -0,0 +1,10 @@ +DROP TRIGGER trigger_crates_set_updated_at ON crates; + DROP TRIGGER trigger_versions_set_updated_at ON versions; + DROP FUNCTION set_updated_at_ignore_downloads(); + CREATE TRIGGER trigger_crates_set_updated_at BEFORE UPDATE + ON crates + FOR EACH ROW EXECUTE PROCEDURE set_updated_at(); + + CREATE TRIGGER trigger_versions_set_updated_at BEFORE UPDATE + ON versions + FOR EACH ROW EXECUTE PROCEDURE set_updated_at(); \ No newline at end of file diff --git a/migrations/20151211122515_dumped_migration_104/up.sql b/migrations/20151211122515_dumped_migration_104/up.sql new file mode 100644 index 00000000000..859f8358397 --- /dev/null +++ b/migrations/20151211122515_dumped_migration_104/up.sql @@ -0,0 +1,19 @@ +CREATE FUNCTION set_updated_at_ignore_downloads() RETURNS trigger AS $$ + BEGIN + IF (NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at AND + NEW.downloads = OLD.downloads) THEN + NEW.updated_at := current_timestamp; + END IF; + RETURN NEW; + END + $$ LANGUAGE plpgsql; + + DROP TRIGGER trigger_crates_set_updated_at ON crates; + DROP TRIGGER trigger_versions_set_updated_at ON versions; + CREATE TRIGGER trigger_crates_set_updated_at BEFORE UPDATE + ON crates + FOR EACH ROW EXECUTE PROCEDURE set_updated_at_ignore_downloads(); + + CREATE TRIGGER trigger_versions_set_updated_at BEFORE UPDATE + ON versions + FOR EACH ROW EXECUTE PROCEDURE set_updated_at_ignore_downloads(); \ No newline at end of file diff --git a/migrations/20160219125609_dumped_migration_105/down.sql b/migrations/20160219125609_dumped_migration_105/down.sql new file mode 100644 index 00000000000..ed5d380aa98 --- /dev/null +++ b/migrations/20160219125609_dumped_migration_105/down.sql @@ -0,0 +1,25 @@ +ALTER TABLE crates ADD COLUMN keywords VARCHAR; + CREATE OR REPLACE FUNCTION trigger_crates_name_search() RETURNS trigger AS $$ + begin + new.textsearchable_index_col := + setweight(to_tsvector('pg_catalog.english', + coalesce(new.name, '')), 'A') || + setweight(to_tsvector('pg_catalog.english', + coalesce(new.keywords, '')), 'B') || + setweight(to_tsvector('pg_catalog.english', + coalesce(new.description, '')), 'C') || + setweight(to_tsvector('pg_catalog.english', + coalesce(new.readme, '')), 'D'); + return new; + end + $$ LANGUAGE plpgsql; + + UPDATE crates SET keywords = ( + SELECT array_to_string(array_agg(keyword), ',') + FROM keywords INNER JOIN crates_keywords + ON keywords.id = crates_keywords.keyword_id + WHERE crates_keywords.crate_id = crates.id + ); + + DROP TRIGGER touch_crate_on_modify_keywords ON crates_keywords; + DROP FUNCTION touch_crate(); \ No newline at end of file diff --git a/migrations/20160219125609_dumped_migration_105/up.sql b/migrations/20160219125609_dumped_migration_105/up.sql new file mode 100644 index 00000000000..304de52a4af --- /dev/null +++ b/migrations/20160219125609_dumped_migration_105/up.sql @@ -0,0 +1,37 @@ +ALTER TABLE crates DROP COLUMN keywords; + CREATE OR REPLACE FUNCTION trigger_crates_name_search() RETURNS trigger AS $$ + DECLARE kws TEXT; + begin + SELECT array_to_string(array_agg(keyword), ',') INTO kws + FROM keywords INNER JOIN crates_keywords + ON keywords.id = crates_keywords.keyword_id + WHERE crates_keywords.crate_id = new.id; + new.textsearchable_index_col := + setweight(to_tsvector('pg_catalog.english', + coalesce(new.name, '')), 'A') || + setweight(to_tsvector('pg_catalog.english', + coalesce(kws, '')), 'B') || + setweight(to_tsvector('pg_catalog.english', + coalesce(new.description, '')), 'C') || + setweight(to_tsvector('pg_catalog.english', + coalesce(new.readme, '')), 'D'); + return new; + end + $$ LANGUAGE plpgsql; + CREATE OR REPLACE FUNCTION touch_crate() RETURNS trigger AS $$ + BEGIN + IF TG_OP = 'DELETE' THEN + UPDATE crates SET updated_at = CURRENT_TIMESTAMP WHERE + id = OLD.crate_id; + RETURN OLD; + ELSE + UPDATE crates SET updated_at = CURRENT_TIMESTAMP WHERE + id = NEW.crate_id; + RETURN NEW; + END IF; + END + $$ LANGUAGE plpgsql; + CREATE TRIGGER touch_crate_on_modify_keywords + AFTER INSERT OR DELETE ON crates_keywords + FOR EACH ROW + EXECUTE PROCEDURE touch_crate(); \ No newline at end of file diff --git a/migrations/20160717173343_dumped_migration_106/down.sql b/migrations/20160717173343_dumped_migration_106/down.sql new file mode 100644 index 00000000000..7ea97171b1a --- /dev/null +++ b/migrations/20160717173343_dumped_migration_106/down.sql @@ -0,0 +1 @@ +CREATE INDEX index_crates_user_id ON crates (user_id); \ No newline at end of file diff --git a/migrations/20160717173343_dumped_migration_106/up.sql b/migrations/20160717173343_dumped_migration_106/up.sql new file mode 100644 index 00000000000..10ed5f50c02 --- /dev/null +++ b/migrations/20160717173343_dumped_migration_106/up.sql @@ -0,0 +1 @@ +DROP INDEX index_crates_user_id; \ No newline at end of file diff --git a/migrations/20160717174005_dumped_migration_107/down.sql b/migrations/20160717174005_dumped_migration_107/down.sql new file mode 100644 index 00000000000..2147b328117 --- /dev/null +++ b/migrations/20160717174005_dumped_migration_107/down.sql @@ -0,0 +1,2 @@ +ALTER TABLE crates ADD CONSTRAINT fk_crates_user_id + FOREIGN KEY (user_id) REFERENCES users (id); \ No newline at end of file diff --git a/migrations/20160717174005_dumped_migration_107/up.sql b/migrations/20160717174005_dumped_migration_107/up.sql new file mode 100644 index 00000000000..01dff878167 --- /dev/null +++ b/migrations/20160717174005_dumped_migration_107/up.sql @@ -0,0 +1 @@ +ALTER TABLE crates DROP CONSTRAINT fk_crates_user_id; \ No newline at end of file diff --git a/migrations/20160717174656_dumped_migration_108/down.sql b/migrations/20160717174656_dumped_migration_108/down.sql new file mode 100644 index 00000000000..4732a467bd3 --- /dev/null +++ b/migrations/20160717174656_dumped_migration_108/down.sql @@ -0,0 +1 @@ +ALTER TABLE crates ADD COLUMN user_id INTEGER NOT NULL; \ No newline at end of file diff --git a/migrations/20160717174656_dumped_migration_108/up.sql b/migrations/20160717174656_dumped_migration_108/up.sql new file mode 100644 index 00000000000..d1c96521910 --- /dev/null +++ b/migrations/20160717174656_dumped_migration_108/up.sql @@ -0,0 +1 @@ +ALTER TABLE crates DROP COLUMN user_id; \ No newline at end of file diff --git a/migrations/20160811151953_dumped_migration_109/down.sql b/migrations/20160811151953_dumped_migration_109/down.sql new file mode 100644 index 00000000000..571fc8f2f3e --- /dev/null +++ b/migrations/20160811151953_dumped_migration_109/down.sql @@ -0,0 +1 @@ +ALTER TABLE users DROP COLUMN gh_id; \ No newline at end of file diff --git a/migrations/20160811151953_dumped_migration_109/up.sql b/migrations/20160811151953_dumped_migration_109/up.sql new file mode 100644 index 00000000000..2425ded4185 --- /dev/null +++ b/migrations/20160811151953_dumped_migration_109/up.sql @@ -0,0 +1 @@ +ALTER TABLE users ADD COLUMN gh_id INTEGER; \ No newline at end of file diff --git a/migrations/20160811151954_dumped_migration_110/down.sql b/migrations/20160811151954_dumped_migration_110/down.sql new file mode 100644 index 00000000000..ebc3dc64018 --- /dev/null +++ b/migrations/20160811151954_dumped_migration_110/down.sql @@ -0,0 +1 @@ +DROP INDEX index_users_gh_id; \ No newline at end of file diff --git a/migrations/20160811151954_dumped_migration_110/up.sql b/migrations/20160811151954_dumped_migration_110/up.sql new file mode 100644 index 00000000000..9af3019a34c --- /dev/null +++ b/migrations/20160811151954_dumped_migration_110/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX index_users_gh_id + ON users (gh_id); \ No newline at end of file diff --git a/migrations/20160812094501_dumped_migration_111/down.sql b/migrations/20160812094501_dumped_migration_111/down.sql new file mode 100644 index 00000000000..1ce277587b0 --- /dev/null +++ b/migrations/20160812094501_dumped_migration_111/down.sql @@ -0,0 +1 @@ +ALTER TABLE users ALTER COLUMN gh_id DROP NOT NULL; \ No newline at end of file diff --git a/migrations/20160812094501_dumped_migration_111/up.sql b/migrations/20160812094501_dumped_migration_111/up.sql new file mode 100644 index 00000000000..048c2360121 --- /dev/null +++ b/migrations/20160812094501_dumped_migration_111/up.sql @@ -0,0 +1 @@ +ALTER TABLE users ALTER COLUMN gh_id SET NOT NULL; \ No newline at end of file diff --git a/migrations/20160812094502_dumped_migration_112/down.sql b/migrations/20160812094502_dumped_migration_112/down.sql new file mode 100644 index 00000000000..b2ebfec1d64 --- /dev/null +++ b/migrations/20160812094502_dumped_migration_112/down.sql @@ -0,0 +1 @@ +DROP INDEX users_gh_id; \ No newline at end of file diff --git a/migrations/20160812094502_dumped_migration_112/up.sql b/migrations/20160812094502_dumped_migration_112/up.sql new file mode 100644 index 00000000000..2eba961f974 --- /dev/null +++ b/migrations/20160812094502_dumped_migration_112/up.sql @@ -0,0 +1 @@ +CREATE UNIQUE INDEX users_gh_id ON users (gh_id) WHERE gh_id > 0; \ No newline at end of file diff --git a/migrations/20161115110541_dumped_migration_113/down.sql b/migrations/20161115110541_dumped_migration_113/down.sql new file mode 100644 index 00000000000..58d5908cef8 --- /dev/null +++ b/migrations/20161115110541_dumped_migration_113/down.sql @@ -0,0 +1 @@ +DROP TABLE categories; \ No newline at end of file diff --git a/migrations/20161115110541_dumped_migration_113/up.sql b/migrations/20161115110541_dumped_migration_113/up.sql new file mode 100644 index 00000000000..d68ae059006 --- /dev/null +++ b/migrations/20161115110541_dumped_migration_113/up.sql @@ -0,0 +1 @@ +CREATE TABLE categories ( id SERIAL PRIMARY KEY, category VARCHAR NOT NULL UNIQUE, slug VARCHAR NOT NULL UNIQUE, description VARCHAR NOT NULL DEFAULT '', crates_cnt INTEGER NOT NULL DEFAULT 0, created_at TIMESTAMP NOT NULL DEFAULT current_timestamp); \ No newline at end of file diff --git a/migrations/20161115111828_dumped_migration_114/down.sql b/migrations/20161115111828_dumped_migration_114/down.sql new file mode 100644 index 00000000000..d8949c9bf15 --- /dev/null +++ b/migrations/20161115111828_dumped_migration_114/down.sql @@ -0,0 +1 @@ +DROP TABLE crates_categories; \ No newline at end of file diff --git a/migrations/20161115111828_dumped_migration_114/up.sql b/migrations/20161115111828_dumped_migration_114/up.sql new file mode 100644 index 00000000000..ad4f7819ea9 --- /dev/null +++ b/migrations/20161115111828_dumped_migration_114/up.sql @@ -0,0 +1 @@ +CREATE TABLE crates_categories ( crate_id INTEGER NOT NULL, category_id INTEGER NOT NULL); \ No newline at end of file diff --git a/migrations/20161115111836_dumped_migration_115/down.sql b/migrations/20161115111836_dumped_migration_115/down.sql new file mode 100644 index 00000000000..bc8f47a5a4d --- /dev/null +++ b/migrations/20161115111836_dumped_migration_115/down.sql @@ -0,0 +1 @@ +ALTER TABLE crates_categories DROP CONSTRAINT fk_crates_categories_crate_id; \ No newline at end of file diff --git a/migrations/20161115111836_dumped_migration_115/up.sql b/migrations/20161115111836_dumped_migration_115/up.sql new file mode 100644 index 00000000000..b98080ac7c4 --- /dev/null +++ b/migrations/20161115111836_dumped_migration_115/up.sql @@ -0,0 +1,2 @@ +ALTER TABLE crates_categories ADD CONSTRAINT fk_crates_categories_crate_id + FOREIGN KEY (crate_id) REFERENCES crates (id); \ No newline at end of file diff --git a/migrations/20161115111846_dumped_migration_116/down.sql b/migrations/20161115111846_dumped_migration_116/down.sql new file mode 100644 index 00000000000..9cbfb746565 --- /dev/null +++ b/migrations/20161115111846_dumped_migration_116/down.sql @@ -0,0 +1 @@ +ALTER TABLE crates_categories DROP CONSTRAINT fk_crates_categories_category_id; \ No newline at end of file diff --git a/migrations/20161115111846_dumped_migration_116/up.sql b/migrations/20161115111846_dumped_migration_116/up.sql new file mode 100644 index 00000000000..f41b661f560 --- /dev/null +++ b/migrations/20161115111846_dumped_migration_116/up.sql @@ -0,0 +1 @@ +ALTER TABLE crates_categories ADD CONSTRAINT fk_crates_categories_category_id FOREIGN KEY (category_id) REFERENCES categories (id) ON DELETE CASCADE; \ No newline at end of file diff --git a/migrations/20161115111853_dumped_migration_117/down.sql b/migrations/20161115111853_dumped_migration_117/down.sql new file mode 100644 index 00000000000..fc15a7eebcf --- /dev/null +++ b/migrations/20161115111853_dumped_migration_117/down.sql @@ -0,0 +1 @@ +DROP INDEX index_crates_categories_crate_id; \ No newline at end of file diff --git a/migrations/20161115111853_dumped_migration_117/up.sql b/migrations/20161115111853_dumped_migration_117/up.sql new file mode 100644 index 00000000000..18f5da418f0 --- /dev/null +++ b/migrations/20161115111853_dumped_migration_117/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX index_crates_categories_crate_id + ON crates_categories (crate_id); \ No newline at end of file diff --git a/migrations/20161115111900_dumped_migration_118/down.sql b/migrations/20161115111900_dumped_migration_118/down.sql new file mode 100644 index 00000000000..b8762c73e83 --- /dev/null +++ b/migrations/20161115111900_dumped_migration_118/down.sql @@ -0,0 +1 @@ +DROP INDEX index_crates_categories_category_id; \ No newline at end of file diff --git a/migrations/20161115111900_dumped_migration_118/up.sql b/migrations/20161115111900_dumped_migration_118/up.sql new file mode 100644 index 00000000000..588900cb8e7 --- /dev/null +++ b/migrations/20161115111900_dumped_migration_118/up.sql @@ -0,0 +1,2 @@ +CREATE INDEX index_crates_categories_category_id + ON crates_categories (category_id); \ No newline at end of file diff --git a/migrations/20161115111957_dumped_migration_119/down.sql b/migrations/20161115111957_dumped_migration_119/down.sql new file mode 100644 index 00000000000..f6f02fe3322 --- /dev/null +++ b/migrations/20161115111957_dumped_migration_119/down.sql @@ -0,0 +1 @@ +DROP TRIGGER trigger_update_categories_crates_cnt ON crates_categories; DROP FUNCTION update_categories_crates_cnt(); DROP TRIGGER touch_crate_on_modify_categories ON crates_categories; \ No newline at end of file diff --git a/migrations/20161115111957_dumped_migration_119/up.sql b/migrations/20161115111957_dumped_migration_119/up.sql new file mode 100644 index 00000000000..02593daa376 --- /dev/null +++ b/migrations/20161115111957_dumped_migration_119/up.sql @@ -0,0 +1 @@ +CREATE FUNCTION update_categories_crates_cnt() RETURNS trigger AS $$ BEGIN IF (TG_OP = 'INSERT') THEN UPDATE categories SET crates_cnt = crates_cnt + 1 WHERE id = NEW.category_id; return NEW; ELSIF (TG_OP = 'DELETE') THEN UPDATE categories SET crates_cnt = crates_cnt - 1 WHERE id = OLD.category_id; return OLD; END IF; END $$ LANGUAGE plpgsql; CREATE TRIGGER trigger_update_categories_crates_cnt BEFORE INSERT OR DELETE ON crates_categories FOR EACH ROW EXECUTE PROCEDURE update_categories_crates_cnt(); CREATE TRIGGER touch_crate_on_modify_categories AFTER INSERT OR DELETE ON crates_categories FOR EACH ROW EXECUTE PROCEDURE touch_crate(); \ No newline at end of file diff --git a/migrations/20170102131034_dumped_migration_120/down.sql b/migrations/20170102131034_dumped_migration_120/down.sql new file mode 100644 index 00000000000..096a6895c10 --- /dev/null +++ b/migrations/20170102131034_dumped_migration_120/down.sql @@ -0,0 +1 @@ +DROP TABLE badges; \ No newline at end of file diff --git a/migrations/20170102131034_dumped_migration_120/up.sql b/migrations/20170102131034_dumped_migration_120/up.sql new file mode 100644 index 00000000000..e64ce086993 --- /dev/null +++ b/migrations/20170102131034_dumped_migration_120/up.sql @@ -0,0 +1 @@ +CREATE TABLE badges ( crate_id INTEGER NOT NULL, badge_type VARCHAR NOT NULL, attributes JSONB NOT NULL); \ No newline at end of file diff --git a/migrations/20170102145236_dumped_migration_121/down.sql b/migrations/20170102145236_dumped_migration_121/down.sql new file mode 100644 index 00000000000..fc1d3b249e6 --- /dev/null +++ b/migrations/20170102145236_dumped_migration_121/down.sql @@ -0,0 +1 @@ +DROP INDEX badges_crate_type; diff --git a/migrations/20170102145236_dumped_migration_121/up.sql b/migrations/20170102145236_dumped_migration_121/up.sql new file mode 100644 index 00000000000..8b425715ece --- /dev/null +++ b/migrations/20170102145236_dumped_migration_121/up.sql @@ -0,0 +1 @@ +CREATE UNIQUE INDEX badges_crate_type ON badges (crate_id, badge_type); \ No newline at end of file diff --git a/migrations/20170304182614_make_schema_compatible_with_diesel/down.sql b/migrations/20170304182614_make_schema_compatible_with_diesel/down.sql new file mode 100644 index 00000000000..1e5e2e13ab1 --- /dev/null +++ b/migrations/20170304182614_make_schema_compatible_with_diesel/down.sql @@ -0,0 +1,6 @@ +CREATE UNIQUE INDEX badges_crate_type ON badges (crate_id, badge_type); +ALTER TABLE badges DROP CONSTRAINT badges_pkey; +ALTER TABLE crates_categories DROP CONSTRAINT crates_categories_pkey; +ALTER TABLE crates_keywords DROP CONSTRAINT crates_keywords_pkey; +ALTER TABLE follows DROP CONSTRAINT follows_pkey; +ALTER TABLE metadata DROP CONSTRAINT metadata_pkey; diff --git a/migrations/20170304182614_make_schema_compatible_with_diesel/up.sql b/migrations/20170304182614_make_schema_compatible_with_diesel/up.sql new file mode 100644 index 00000000000..2a92515164a --- /dev/null +++ b/migrations/20170304182614_make_schema_compatible_with_diesel/up.sql @@ -0,0 +1,6 @@ +DROP INDEX badges_crate_type; +ALTER TABLE badges ADD PRIMARY KEY (crate_id, badge_type); +ALTER TABLE crates_categories ADD PRIMARY KEY (crate_id, category_id); +ALTER TABLE crates_keywords ADD PRIMARY KEY (crate_id, keyword_id); +ALTER TABLE follows ADD PRIMARY KEY (user_id, crate_id); +ALTER TABLE metadata ADD PRIMARY KEY (total_downloads); diff --git a/migrations/20170305095748_create_reserved_crate_names/down.sql b/migrations/20170305095748_create_reserved_crate_names/down.sql new file mode 100644 index 00000000000..12337d56e59 --- /dev/null +++ b/migrations/20170305095748_create_reserved_crate_names/down.sql @@ -0,0 +1,3 @@ +DROP TRIGGER trigger_ensure_crate_name_not_reserved ON crates; +DROP FUNCTION ensure_crate_name_not_reserved(); +DROP TABLE reserved_crate_names; diff --git a/migrations/20170305095748_create_reserved_crate_names/up.sql b/migrations/20170305095748_create_reserved_crate_names/up.sql new file mode 100644 index 00000000000..45924778a63 --- /dev/null +++ b/migrations/20170305095748_create_reserved_crate_names/up.sql @@ -0,0 +1,27 @@ +CREATE TABLE reserved_crate_names ( + name TEXT PRIMARY KEY +); +CREATE UNIQUE INDEX ON reserved_crate_names (canon_crate_name(name)); +INSERT INTO reserved_crate_names (name) VALUES + ('alloc'), ('arena'), ('ast'), ('builtins'), ('collections'), + ('compiler-builtins'), ('compiler-rt'), ('compiletest'), ('core'), ('coretest'), + ('debug'), ('driver'), ('flate'), ('fmt_macros'), ('grammar'), ('graphviz'), + ('macro'), ('macros'), ('proc_macro'), ('rbml'), ('rust-installer'), ('rustbook'), + ('rustc'), ('rustc_back'), ('rustc_borrowck'), ('rustc_driver'), ('rustc_llvm'), + ('rustc_resolve'), ('rustc_trans'), ('rustc_typeck'), ('rustdoc'), ('rustllvm'), + ('rustuv'), ('serialize'), ('std'), ('syntax'), ('test'), ('unicode'); + +CREATE FUNCTION ensure_crate_name_not_reserved() RETURNS trigger AS $$ +BEGIN + IF canon_crate_name(NEW.name) IN ( + SELECT canon_crate_name(name) FROM reserved_crate_names + ) THEN + RAISE EXCEPTION 'cannot upload crate with reserved name'; + END IF; + RETURN NEW; +END; +$$ LANGUAGE plpgsql; + +CREATE TRIGGER trigger_ensure_crate_name_not_reserved +BEFORE INSERT OR UPDATE ON crates +FOR EACH ROW EXECUTE PROCEDURE ensure_crate_name_not_reserved(); diff --git a/src/app.rs b/src/app.rs index d5ad6461227..764908ae944 100644 --- a/src/app.rs +++ b/src/app.rs @@ -18,6 +18,9 @@ pub struct App { /// The database connection pool pub database: db::Pool, + /// The database connection pool + pub diesel_database: db::DieselPool, + /// The GitHub OAuth2 configuration pub github: oauth2::Config, pub bucket: s3::Bucket, @@ -50,10 +53,15 @@ impl App { .pool_size(if config.env == ::Env::Production {10} else {1}) .helper_threads(if config.env == ::Env::Production {3} else {1}) .build(); + let diesel_db_config = r2d2::Config::builder() + .pool_size(if config.env == ::Env::Production {1} else {1}) + .helper_threads(if config.env == ::Env::Production {3} else {1}) + .build(); let repo = git2::Repository::open(&config.git_repo_checkout).unwrap(); return App { database: db::pool(&config.db_url, db_config), + diesel_database: db::diesel_pool(&config.db_url, diesel_db_config), github: github, bucket: s3::Bucket::new(config.s3_bucket.clone(), config.s3_region.clone(), diff --git a/src/bin/migrate.rs b/src/bin/migrate.rs index fa905a7d7cf..2bfca78c783 100644 --- a/src/bin/migrate.rs +++ b/src/bin/migrate.rs @@ -1,939 +1,46 @@ #![deny(warnings)] -extern crate cargo_registry; -extern crate migrate; -extern crate postgres; - +#[macro_use] +extern crate diesel; +extern crate dotenv; + +use diesel::*; +use diesel::migrations::setup_database; +use diesel::pg::PgConnection; +use dotenv::dotenv; use std::env; -use std::collections::HashSet; -use migrate::Migration; - -use cargo_registry::krate::Crate; -use cargo_registry::model::Model; - -#[allow(dead_code)] -fn main() { - let conn = cargo_registry::db::connect_now(); - let migrations = migrations(); - - let arg = env::args().nth(1); - if arg.as_ref().map(|s| &s[..]) == Some("rollback") { - rollback(conn.transaction().unwrap(), migrations).unwrap(); - } else { - apply(conn.transaction().unwrap(), migrations).unwrap(); - } -} -fn apply(tx: postgres::transaction::Transaction, - migrations: Vec) -> postgres::Result<()> { - let mut mgr = migrate::Manager::new(tx)?; - for m in migrations.into_iter() { - mgr.apply(m)?; +table! { + information_schema.tables (table_name) { + table_name -> Text, } - mgr.set_commit(); - mgr.finish() } -fn rollback(tx: postgres::transaction::Transaction, - migrations: Vec) -> postgres::Result<()> { - let mut mgr = migrate::Manager::new(tx)?; - for m in migrations.into_iter().rev() { - if mgr.contains(m.version()) { - mgr.rollback(m)?; - break - } - } - mgr.set_commit(); - mgr.finish() -} - -fn migrations() -> Vec { - let migrations = vec![ - Migration::add_table(20140924113530, "users", " - id SERIAL PRIMARY KEY, - email VARCHAR NOT NULL UNIQUE, - gh_access_token VARCHAR NOT NULL, - api_token VARCHAR NOT NULL - "), - Migration::add_table(20140924114003, "packages", " - id SERIAL PRIMARY KEY, - name VARCHAR NOT NULL UNIQUE, - user_id INTEGER NOT NULL - "), - Migration::add_table(20140924114059, "versions", " - id SERIAL PRIMARY KEY, - package_id INTEGER NOT NULL, - num VARCHAR NOT NULL - "), - Migration::run(20140924115329, - &format!("ALTER TABLE versions ADD CONSTRAINT \ - unique_num UNIQUE (package_id, num)"), - &format!("ALTER TABLE versions DROP CONSTRAINT \ - unique_num")), - Migration::add_table(20140924120803, "version_dependencies", " - version_id INTEGER NOT NULL, - depends_on_id INTEGER NOT NULL - "), - Migration::add_column(20140925132248, "packages", "updated_at", - "TIMESTAMP NOT NULL DEFAULT now()"), - Migration::add_column(20140925132249, "packages", "created_at", - "TIMESTAMP NOT NULL DEFAULT now()"), - Migration::new(20140925132250, |tx| { - tx.execute("UPDATE packages SET updated_at = now() \ - WHERE updated_at IS NULL", &[])?; - tx.execute("UPDATE packages SET created_at = now() \ - WHERE created_at IS NULL", &[])?; - Ok(()) - }, |_| Ok(())), - Migration::add_column(20140925132251, "versions", "updated_at", - "TIMESTAMP NOT NULL DEFAULT now()"), - Migration::add_column(20140925132252, "versions", "created_at", - "TIMESTAMP NOT NULL DEFAULT now()"), - Migration::new(20140925132253, |tx| { - tx.execute("UPDATE versions SET updated_at = now() \ - WHERE updated_at IS NULL", &[])?; - tx.execute("UPDATE versions SET created_at = now() \ - WHERE created_at IS NULL", &[])?; - Ok(()) - }, |_| Ok(())), - Migration::new(20140925132254, |tx| { - tx.execute("ALTER TABLE versions ALTER COLUMN updated_at \ - DROP DEFAULT", &[])?; - tx.execute("ALTER TABLE versions ALTER COLUMN created_at \ - DROP DEFAULT", &[])?; - tx.execute("ALTER TABLE packages ALTER COLUMN updated_at \ - DROP DEFAULT", &[])?; - tx.execute("ALTER TABLE packages ALTER COLUMN created_at \ - DROP DEFAULT", &[])?; - Ok(()) - }, |_| Ok(())), - Migration::add_table(20140925153704, "metadata", " - total_downloads BIGINT NOT NULL - "), - Migration::new(20140925153705, |tx| { - tx.execute("INSERT INTO metadata (total_downloads) \ - VALUES ($1)", &[&0i64])?; - Ok(()) - }, |tx| { - tx.execute("DELETE FROM metadata", &[])?; Ok(()) - }), - Migration::add_column(20140925161623, "packages", "downloads", - "INTEGER NOT NULL DEFAULT 0"), - Migration::add_column(20140925161624, "versions", "downloads", - "INTEGER NOT NULL DEFAULT 0"), - Migration::new(20140925161625, |tx| { - tx.execute("ALTER TABLE versions ALTER COLUMN downloads \ - DROP DEFAULT", &[])?; - tx.execute("ALTER TABLE packages ALTER COLUMN downloads \ - DROP DEFAULT", &[])?; - Ok(()) - }, |_| Ok(())), - Migration::add_column(20140926130044, "packages", "max_version", - "VARCHAR"), - Migration::new(20140926130045, |tx| { - let stmt = tx.prepare("SELECT * FROM packages")?; - let rows = stmt.query(&[])?; - for row in rows.iter() { - let pkg: Crate = Model::from_row(&row); - let versions = pkg.versions(tx).unwrap(); - let v = versions.iter().max_by_key(|v| &v.num).unwrap(); - let max = v.num.to_string(); - tx.execute("UPDATE packages SET max_version = $1 \ - WHERE id = $2", - &[&max, &pkg.id])?; - } - Ok(()) - }, |_| Ok(())), - Migration::new(20140926130046, |tx| { - tx.execute("ALTER TABLE versions ALTER COLUMN downloads \ - SET NOT NULL", &[])?; - Ok(()) - }, |tx| { - tx.execute("ALTER TABLE versions ALTER COLUMN downloads \ - DROP NOT NULL", &[])?; - Ok(()) - }), - Migration::new(20140926174020, |tx| { - tx.execute("ALTER TABLE packages RENAME TO crates", &[])?; - tx.execute("ALTER TABLE versions RENAME COLUMN package_id \ - TO crate_id", &[])?; - Ok(()) - }, |tx| { - tx.execute("ALTER TABLE crates RENAME TO packages", &[])?; - tx.execute("ALTER TABLE versions RENAME COLUMN crate_id \ - TO package_id", &[])?; - Ok(()) - }), - Migration::run(20140929103749, - "CREATE INDEX index_crate_updated_at ON crates (updated_at)", - "DROP INDEX index_crate_updated_at"), - Migration::run(20140929103750, - "CREATE INDEX index_crate_created_at ON crates (created_at)", - "DROP INDEX index_crate_created_at"), - Migration::run(20140929103751, - "CREATE INDEX index_crate_downloads ON crates (downloads)", - "DROP INDEX index_crate_downloads"), - Migration::run(20140929103752, - "CREATE INDEX index_version_crate_id ON versions (crate_id)", - "DROP INDEX index_version_crate_id"), - Migration::run(20140929103753, - "CREATE INDEX index_version_num ON versions (num)", - "DROP INDEX index_version_num"), - Migration::run(20140929103754, - "CREATE INDEX index_version_dependencies_version_id \ - ON version_dependencies (version_id)", - "DROP INDEX index_version_dependencies_version_id"), - Migration::run(20140929103755, - "CREATE INDEX index_version_dependencies_depends_on_id \ - ON version_dependencies (depends_on_id)", - "DROP INDEX index_version_dependencies_depends_on_id"), - Migration::add_table(20140929103756, "crate_downloads", " - id SERIAL PRIMARY KEY, - crate_id INTEGER NOT NULL, - downloads INTEGER NOT NULL, - date TIMESTAMP NOT NULL - "), - Migration::run(20140929103757, - "CREATE INDEX index_crate_downloads_crate_id \ - ON crate_downloads (crate_id)", - "DROP INDEX index_crate_downloads_crate_id"), - Migration::run(20140929103758, - "CREATE INDEX index_crate_downloads_date \ - ON crate_downloads (date(date))", - "DROP INDEX index_crate_downloads_date"), - Migration::add_table(20140929103759, "version_downloads", " - id SERIAL PRIMARY KEY, - version_id INTEGER NOT NULL, - downloads INTEGER NOT NULL, - counted INTEGER NOT NULL, - date TIMESTAMP NOT NULL, - processed BOOLEAN NOT NULL - "), - Migration::run(20140929103760, - "CREATE INDEX index_version_downloads_version_id \ - ON version_downloads (version_id)", - "DROP INDEX index_version_downloads_version_id"), - Migration::run(20140929103761, - "CREATE INDEX index_version_downloads_date \ - ON version_downloads (date(date))", - "DROP INDEX index_version_downloads_date"), - Migration::run(20140929103763, - "CREATE INDEX index_version_downloads_processed \ - ON version_downloads (processed) - WHERE processed = FALSE", - "DROP INDEX index_version_downloads_processed"), - Migration::run(20140929185718, - "CREATE INDEX index_crates_name_search \ - ON crates USING gin(to_tsvector('english', name))", - "DROP INDEX index_crates_name_search"), - Migration::run(20140930082104, - "DROP TABLE version_dependencies", - "CREATE TABLE version_dependencies ( - version_id INTEGER - )"), - Migration::add_table(20140930082105, "dependencies", " - id SERIAL PRIMARY KEY, - version_id INTEGER NOT NULL, - crate_id INTEGER NOT NULL, - req VARCHAR NOT NULL, - optional BOOLEAN NOT NULL, - default_features BOOLEAN NOT NULL, - features VARCHAR NOT NULL - "), - Migration::add_column(20140930085441, "versions", "features", - "VARCHAR"), - Migration::run(20140930203145, - "CREATE INDEX index_dependencies_version_id \ - ON dependencies (version_id)", - "DROP INDEX index_dependencies_version_id"), - Migration::run(20140930203146, - "CREATE INDEX index_dependencies_crate_id \ - ON dependencies (crate_id)", - "DROP INDEX index_dependencies_crate_id"), - Migration::add_column(20141001190227, "users", "gh_login", - "VARCHAR NOT NULL"), - Migration::add_column(20141001190228, "users", "name", "VARCHAR"), - Migration::run(20141001190229, - "CREATE INDEX index_users_gh_login \ - ON users (gh_login)", - "DROP INDEX index_users_gh_login"), - Migration::run(20141001190230, - "ALTER TABLE users ALTER COLUMN email DROP NOT NULL", - "ALTER TABLE users ALTER COLUMN email SET NOT NULL"), - Migration::add_column(20141001190231, "users", "gh_avatar", "VARCHAR"), - Migration::run(20141002195939, - "CREATE INDEX index_crates_user_id \ - ON crates (user_id)", - "DROP INDEX index_crates_user_id"), - Migration::add_table(20141002195940, "follows", " - user_id INTEGER NOT NULL, - crate_id INTEGER NOT NULL - "), - Migration::run(20141002195941, - "CREATE INDEX index_follows_user_id \ - ON follows (user_id)", - "DROP INDEX index_follows_user_id"), - foreign_key(20141002222426, "crate_downloads", "crate_id", "crates (id)"), - foreign_key(20141002222427, "crates", "user_id", "users (id)"), - foreign_key(20141002222428, "dependencies", "version_id", "versions (id)"), - foreign_key(20141002222429, "dependencies", "crate_id", "crates (id)"), - foreign_key(20141002222430, "follows", "crate_id", "crates (id)"), - foreign_key(20141002222431, "version_downloads", "version_id", - "versions (id)"), - foreign_key(20141002222432, "versions", "crate_id", "crates (id)"), - foreign_key(20141002222433, "follows", "user_id", "users (id)"), - Migration::add_table(20141007131146, "version_authors", " - id SERIAL PRIMARY KEY, - version_id INTEGER NOT NULL, - user_id INTEGER, - name VARCHAR NOT NULL - "), - foreign_key(20141007131147, "version_authors", "user_id", "users (id)"), - foreign_key(20141007131148, "version_authors", "version_id", "versions (id)"), - index(20141007131149, "version_authors", "version_id"), - - Migration::add_table(20141007131735, "crate_owners", " - id SERIAL PRIMARY KEY, - crate_id INTEGER NOT NULL, - user_id INTEGER NOT NULL, - created_at TIMESTAMP NOT NULL, - created_by INTEGER - "), - foreign_key(20141007131736, "crate_owners", "user_id", "users (id)"), - foreign_key(20141007131737, "crate_owners", "created_by", "users (id)"), - foreign_key(20141007131738, "crate_owners", "crate_id", "crates (id)"), - index(20141007131739, "crate_owners", "crate_id"), - Migration::add_column(20141007131740, "crate_owners", "deleted", - "BOOLEAN NOT NULL"), - Migration::add_column(20141007131741, "crate_owners", "updated_at", - "TIMESTAMP NOT NULL"), - Migration::add_column(20141007171515, "crates", "description", - "VARCHAR"), - Migration::add_column(20141007171516, "crates", "homepage", - "VARCHAR"), - Migration::add_column(20141007171517, "crates", "documentation", - "VARCHAR"), - Migration::add_column(20141010150327, "crates", "readme", "VARCHAR"), - Migration::add_column(20141013115510, "versions", "yanked", - "BOOLEAN DEFAULT FALSE"), - Migration::add_column(20141020175647, "crates", - "textsearchable_index_col", "tsvector"), - Migration::run(20141020175648, - "DROP INDEX index_crates_name_search", - "CREATE INDEX index_crates_name_search \ - ON crates USING gin(to_tsvector('english', name))"), - Migration::run(20141020175649, - "CREATE INDEX index_crates_name_search \ - ON crates USING gin(textsearchable_index_col)", - "DROP INDEX index_crates_name_search"), - - // http://www.postgresql.org/docs/8.3/static/textsearch-controls.html - // http://www.postgresql.org/docs/8.3/static/textsearch-features.html - Migration::new(20141020175650, |tx| { - tx.batch_execute(" - CREATE FUNCTION trigger_crates_name_search() RETURNS trigger AS $$ - begin - new.textsearchable_index_col := - setweight(to_tsvector('pg_catalog.english', - coalesce(new.name, '')), 'A') || - setweight(to_tsvector('pg_catalog.english', - coalesce(new.keywords, '')), 'B') || - setweight(to_tsvector('pg_catalog.english', - coalesce(new.description, '')), 'C') || - setweight(to_tsvector('pg_catalog.english', - coalesce(new.readme, '')), 'D'); - return new; - end - $$ LANGUAGE plpgsql; - - CREATE TRIGGER trigger_crates_tsvector_update BEFORE INSERT OR UPDATE - ON crates - FOR EACH ROW EXECUTE PROCEDURE trigger_crates_name_search(); - ")?; - Ok(()) - - }, |tx| { - tx.execute("DROP TRIGGER trigger_crates_tsvector_update - ON crates", &[])?; - tx.execute("DROP FUNCTION trigger_crates_name_search()", &[])?; - Ok(()) - }), - Migration::add_column(20141020175651, "crates", "keywords", "varchar"), - Migration::add_table(20141021103503, "keywords", " - id SERIAL PRIMARY KEY, - keyword VARCHAR NOT NULL UNIQUE, - crates_cnt INTEGER NOT NULL, - created_at TIMESTAMP NOT NULL - "), - Migration::add_table(20141021103504, "crates_keywords", " - crate_id INTEGER NOT NULL, - keyword_id INTEGER NOT NULL - "), - foreign_key(20141021103505, "crates_keywords", "crate_id", "crates (id)"), - foreign_key(20141021103506, "crates_keywords", "keyword_id", - "keywords (id)"), - index(20141021103507, "crates_keywords", "crate_id"), - index(20141021103508, "crates_keywords", "keyword_id"), - index(20141021103509, "keywords", "keyword"), - index(20141021103510, "keywords", "crates_cnt"), - Migration::add_column(20141022110441, "dependencies", "target", "varchar"), - Migration::add_column(20141023180230, "crates", "license", "varchar"), - Migration::add_column(20141023180231, "crates", "repository", "varchar"), - - Migration::new(20141112082527, |tx| { - tx.execute("ALTER TABLE users DROP CONSTRAINT IF \ - EXISTS users_email_key", &[])?; - Ok(()) - - }, |_| Ok(())), - Migration::add_column(20141120162357, "dependencies", "kind", "INTEGER"), - Migration::new(20141121191309, |tx| { - tx.execute("ALTER TABLE crates DROP CONSTRAINT \ - packages_name_key", &[])?; - tx.execute("CREATE UNIQUE INDEX index_crates_name \ - ON crates (lower(name))", &[])?; - Ok(()) - - }, |tx| { - tx.execute("DROP INDEX index_crates_name", &[])?; - tx.execute("ALTER TABLE crates ADD CONSTRAINT packages_name_key \ - UNIQUE (name)", &[])?; - Ok(()) - }), - Migration::new(20150209202206, |tx| { - fix_duplicate_crate_owners(tx)?; - tx.execute("ALTER TABLE crate_owners ADD CONSTRAINT \ - crate_owners_unique_user_per_crate \ - UNIQUE (user_id, crate_id)", &[])?; - Ok(()) - }, |tx| { - tx.execute("ALTER TABLE crate_owners DROP CONSTRAINT \ - crate_owners_unique_user_per_crate", &[])?; - Ok(()) - }), - Migration::new(20150319224700, |tx| { - tx.execute(" - CREATE FUNCTION canon_crate_name(text) RETURNS text AS $$ - SELECT replace(lower($1), '-', '_') - $$ LANGUAGE SQL - ", &[])?; - Ok(()) - }, |tx| { - tx.execute("DROP FUNCTION canon_crate_name(text)", &[])?; - Ok(()) - }), - Migration::new(20150319224701, |tx| { - tx.execute("DROP INDEX index_crates_name", &[])?; - tx.execute("CREATE UNIQUE INDEX index_crates_name \ - ON crates (canon_crate_name(name))", &[])?; - Ok(()) - }, |tx| { - tx.execute("DROP INDEX index_crates_name", &[])?; - tx.execute("CREATE UNIQUE INDEX index_crates_name \ - ON crates (lower(name))", &[])?; - Ok(()) - }), - Migration::new(20150320174400, |tx| { - tx.execute("CREATE INDEX index_keywords_lower_keyword ON keywords (lower(keyword))", - &[])?; - Ok(()) - }, |tx| { - tx.execute("DROP INDEX index_keywords_lower_keyword", &[])?; - Ok(()) - }), - Migration::add_column(20150715170350, "crate_owners", "owner_kind", - "INTEGER NOT NULL DEFAULT 0"), - Migration::run(20150804170127, - "ALTER TABLE crate_owners ALTER owner_kind DROP DEFAULT", - "ALTER TABLE crate_owners ALTER owner_kind SET DEFAULT 0", - ), - Migration::add_table(20150804170128, "teams", " - id SERIAL PRIMARY KEY, - login VARCHAR NOT NULL UNIQUE, - github_id INTEGER NOT NULL UNIQUE, - name VARCHAR, - avatar VARCHAR - "), - Migration::run(20150804170129, - "ALTER TABLE crate_owners RENAME user_id TO owner_id", - "ALTER TABLE crate_owners RENAME owner_id TO user_id", - ), - undo_foreign_key(20150804170130, "crate_owners", "user_id", - "owner_id", "users (id)"), - Migration::new(20150818112907, |tx| { - tx.execute("ALTER TABLE crate_owners DROP CONSTRAINT \ - crate_owners_unique_user_per_crate", &[])?; - tx.execute("ALTER TABLE crate_owners ADD CONSTRAINT \ - crate_owners_unique_owner_per_crate \ - UNIQUE (owner_id, crate_id, owner_kind)", &[])?; - Ok(()) - }, |tx| { - tx.execute("ALTER TABLE crate_owners DROP CONSTRAINT \ - crate_owners_unique_owner_per_crate", &[])?; - tx.execute("ALTER TABLE crate_owners ADD CONSTRAINT \ - crate_owners_unique_user_per_crate \ - UNIQUE (owner_id, crate_id)", &[])?; - Ok(()) - }), - Migration::add_column(20151118135514, "crates", "max_upload_size", - "INTEGER"), - Migration::new(20151126095136, |tx| { - tx.batch_execute(" - ALTER TABLE version_downloads ALTER downloads SET DEFAULT 1; - ALTER TABLE version_downloads ALTER counted SET DEFAULT 0; - ALTER TABLE version_downloads ALTER date SET DEFAULT current_date; - ALTER TABLE version_downloads ALTER processed SET DEFAULT 'f'; - - ALTER TABLE keywords ALTER created_at SET DEFAULT current_timestamp; - ALTER TABLE keywords ALTER crates_cnt SET DEFAULT 0; - - ALTER TABLE crates ALTER created_at SET DEFAULT current_timestamp; - ALTER TABLE crates ALTER updated_at SET DEFAULT current_timestamp; - ALTER TABLE crates ALTER downloads SET DEFAULT 0; - ALTER TABLE crates ALTER max_version SET DEFAULT '0.0.0'; - - ALTER TABLE crate_owners ALTER created_at SET DEFAULT current_timestamp; - ALTER TABLE crate_owners ALTER updated_at SET DEFAULT current_timestamp; - ALTER TABLE crate_owners ALTER deleted SET DEFAULT 'f'; - - ALTER TABLE versions ALTER created_at SET DEFAULT current_timestamp; - ALTER TABLE versions ALTER updated_at SET DEFAULT current_timestamp; - ALTER TABLE versions ALTER downloads SET DEFAULT 0; - - CREATE FUNCTION set_updated_at() RETURNS trigger AS $$ - BEGIN - IF (NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at) THEN - NEW.updated_at := current_timestamp; - END IF; - RETURN NEW; - END - $$ LANGUAGE plpgsql; - - CREATE FUNCTION update_keywords_crates_cnt() RETURNS trigger AS $$ - BEGIN - IF (TG_OP = 'INSERT') THEN - UPDATE keywords SET crates_cnt = crates_cnt + 1 WHERE id = NEW.keyword_id; - return NEW; - ELSIF (TG_OP = 'DELETE') THEN - UPDATE keywords SET crates_cnt = crates_cnt - 1 WHERE id = OLD.keyword_id; - return OLD; - END IF; - END - $$ LANGUAGE plpgsql; - - CREATE TRIGGER trigger_update_keywords_crates_cnt BEFORE INSERT OR DELETE - ON crates_keywords - FOR EACH ROW EXECUTE PROCEDURE update_keywords_crates_cnt(); - - CREATE TRIGGER trigger_crate_owners_set_updated_at BEFORE UPDATE - ON crate_owners - FOR EACH ROW EXECUTE PROCEDURE set_updated_at(); - - CREATE TRIGGER trigger_crates_set_updated_at BEFORE UPDATE - ON crates - FOR EACH ROW EXECUTE PROCEDURE set_updated_at(); - - CREATE TRIGGER trigger_versions_set_updated_at BEFORE UPDATE - ON versions - FOR EACH ROW EXECUTE PROCEDURE set_updated_at(); - ")?; - Ok(()) - - }, |tx| { - tx.batch_execute(" - ALTER TABLE version_downloads ALTER downloads DROP DEFAULT; - ALTER TABLE version_downloads ALTER counted DROP DEFAULT; - ALTER TABLE version_downloads ALTER date DROP DEFAULT; - ALTER TABLE version_downloads ALTER processed DROP DEFAULT; - - ALTER TABLE keywords ALTER created_at DROP DEFAULT; - ALTER TABLE keywords ALTER crates_cnt DROP DEFAULT; - - ALTER TABLE crates ALTER created_at DROP DEFAULT; - ALTER TABLE crates ALTER updated_at DROP DEFAULT; - ALTER TABLE crates ALTER downloads DROP DEFAULT; - ALTER TABLE crates ALTER max_version DROP DEFAULT; - - ALTER TABLE crate_owners ALTER created_at DROP DEFAULT; - ALTER TABLE crate_owners ALTER updated_at DROP DEFAULT; - ALTER TABLE crate_owners ALTER deleted DROP DEFAULT; - - ALTER TABLE versions ALTER created_at DROP DEFAULT; - ALTER TABLE versions ALTER updated_at DROP DEFAULT; - ALTER TABLE versions ALTER downloads DROP DEFAULT; - - DROP TRIGGER trigger_update_keywords_crates_cnt ON crates_keywords; - DROP FUNCTION update_keywords_crates_cnt(); - - DROP TRIGGER trigger_crate_owners_set_updated_at ON crate_owners; - DROP TRIGGER trigger_crates_set_updated_at ON crates; - DROP TRIGGER trigger_versions_set_updated_at ON versions; - - DROP FUNCTION set_updated_at(); - ")?; - Ok(()) - }), - Migration::new(20151211122515, |tx| { - tx.batch_execute(" - CREATE FUNCTION set_updated_at_ignore_downloads() RETURNS trigger AS $$ - BEGIN - IF (NEW.updated_at IS NOT DISTINCT FROM OLD.updated_at AND - NEW.downloads = OLD.downloads) THEN - NEW.updated_at := current_timestamp; - END IF; - RETURN NEW; - END - $$ LANGUAGE plpgsql; - - DROP TRIGGER trigger_crates_set_updated_at ON crates; - DROP TRIGGER trigger_versions_set_updated_at ON versions; - CREATE TRIGGER trigger_crates_set_updated_at BEFORE UPDATE - ON crates - FOR EACH ROW EXECUTE PROCEDURE set_updated_at_ignore_downloads(); - - CREATE TRIGGER trigger_versions_set_updated_at BEFORE UPDATE - ON versions - FOR EACH ROW EXECUTE PROCEDURE set_updated_at_ignore_downloads(); - ")?; - Ok(()) - }, |tx| { - tx.batch_execute(" - DROP TRIGGER trigger_crates_set_updated_at ON crates; - DROP TRIGGER trigger_versions_set_updated_at ON versions; - DROP FUNCTION set_updated_at_ignore_downloads(); - CREATE TRIGGER trigger_crates_set_updated_at BEFORE UPDATE - ON crates - FOR EACH ROW EXECUTE PROCEDURE set_updated_at(); - - CREATE TRIGGER trigger_versions_set_updated_at BEFORE UPDATE - ON versions - FOR EACH ROW EXECUTE PROCEDURE set_updated_at(); - ")?; - Ok(()) - }), - Migration::new(20160219125609, |tx| { - tx.batch_execute(" - ALTER TABLE crates DROP COLUMN keywords; - CREATE OR REPLACE FUNCTION trigger_crates_name_search() RETURNS trigger AS $$ - DECLARE kws TEXT; - begin - SELECT array_to_string(array_agg(keyword), ',') INTO kws - FROM keywords INNER JOIN crates_keywords - ON keywords.id = crates_keywords.keyword_id - WHERE crates_keywords.crate_id = new.id; - new.textsearchable_index_col := - setweight(to_tsvector('pg_catalog.english', - coalesce(new.name, '')), 'A') || - setweight(to_tsvector('pg_catalog.english', - coalesce(kws, '')), 'B') || - setweight(to_tsvector('pg_catalog.english', - coalesce(new.description, '')), 'C') || - setweight(to_tsvector('pg_catalog.english', - coalesce(new.readme, '')), 'D'); - return new; - end - $$ LANGUAGE plpgsql; - CREATE OR REPLACE FUNCTION touch_crate() RETURNS trigger AS $$ - BEGIN - IF TG_OP = 'DELETE' THEN - UPDATE crates SET updated_at = CURRENT_TIMESTAMP WHERE - id = OLD.crate_id; - RETURN OLD; - ELSE - UPDATE crates SET updated_at = CURRENT_TIMESTAMP WHERE - id = NEW.crate_id; - RETURN NEW; - END IF; - END - $$ LANGUAGE plpgsql; - CREATE TRIGGER touch_crate_on_modify_keywords - AFTER INSERT OR DELETE ON crates_keywords - FOR EACH ROW - EXECUTE PROCEDURE touch_crate(); - ") - }, |tx| { - tx.batch_execute(" - ALTER TABLE crates ADD COLUMN keywords VARCHAR; - CREATE OR REPLACE FUNCTION trigger_crates_name_search() RETURNS trigger AS $$ - begin - new.textsearchable_index_col := - setweight(to_tsvector('pg_catalog.english', - coalesce(new.name, '')), 'A') || - setweight(to_tsvector('pg_catalog.english', - coalesce(new.keywords, '')), 'B') || - setweight(to_tsvector('pg_catalog.english', - coalesce(new.description, '')), 'C') || - setweight(to_tsvector('pg_catalog.english', - coalesce(new.readme, '')), 'D'); - return new; - end - $$ LANGUAGE plpgsql; - - UPDATE crates SET keywords = ( - SELECT array_to_string(array_agg(keyword), ',') - FROM keywords INNER JOIN crates_keywords - ON keywords.id = crates_keywords.keyword_id - WHERE crates_keywords.crate_id = crates.id - ); - - DROP TRIGGER touch_crate_on_modify_keywords ON crates_keywords; - DROP FUNCTION touch_crate(); - ") - }), - Migration::new(20160326123149, |tx| { - use postgres::error::{Error, SqlState}; - - for row in tx.query("SELECT id FROM keywords ORDER BY id", &[])?.iter() { - let kw_id: i32 = row.get(0); - let err = { - let tx = tx.transaction()?; - let res = tx.execute("UPDATE keywords SET keyword = LOWER(keyword) - WHERE id = $1", &[&kw_id]); - match res { - Ok(n) => { - assert_eq!(n, 1); - tx.commit()?; - continue; - }, - Err(e) => /* Rollback update, fall through */ e - } - }; - - match err { - Error::Db(ref e) if e.code == SqlState::UniqueViolation => { - // There is already a lower-case version of this keyword. - // Merge into the other one. - let target_id: i32 = tx.query(" - SELECT id FROM keywords WHERE keyword = LOWER(( - SELECT keyword FROM keywords WHERE id = $1 - )) - ", &[&kw_id])?.get(0).get(0); - - tx.batch_execute(&format!(" - UPDATE crates_keywords SET keyword_id = {} - WHERE keyword_id = {}; - UPDATE keywords SET crates_cnt = crates_cnt + ( - SELECT crates_cnt FROM keywords WHERE id = {} - ) WHERE id = {}; - DELETE FROM keywords WHERE id = {}; - ", target_id, kw_id, kw_id, target_id, kw_id))?; - }, - e => return Err(e) - } - } - - Ok(()) - }, |_tx| { - Ok(()) - }), - Migration::run(20160717173343, - "DROP INDEX index_crates_user_id", - "CREATE INDEX index_crates_user_id \ - ON crates (user_id)", - ), - undo_foreign_key(20160717174005, "crates", "user_id", - "user_id", "users (id)"), - Migration::run(20160717174656, - "ALTER TABLE crates DROP COLUMN user_id", - "ALTER TABLE crates ADD COLUMN user_id INTEGER NOT NULL", - ), - - Migration::add_column(20160811151953, "users", "gh_id", "INTEGER"), - index(20160811151954, "users", "gh_id"), - Migration::new(20160812094501, |tx| { - tx.execute("ALTER TABLE users ALTER COLUMN gh_id \ - SET NOT NULL", &[])?; - Ok(()) - }, |tx| { - tx.execute("ALTER TABLE users ALTER COLUMN gh_id \ - DROP NOT NULL", &[])?; - Ok(()) - }), - Migration::new(20160812094502, |tx| { - // Enusre that gh_id is always unique (sure hope it is), but - // only where the id is > 0. Historically we didn't track id, and we - // had to fill it in at one point after-the-fact. User rows that - // couldn't be resolved either have a github id of 0 or -1 so they - // can't ever be logged into again. - tx.execute("CREATE UNIQUE INDEX users_gh_id \ - ON users (gh_id) WHERE gh_id > 0", &[])?; - Ok(()) - }, |tx| { - tx.execute("DROP INDEX users_gh_id", &[])?; - Ok(()) - }), - Migration::add_table(20161115110541, "categories", " \ - id SERIAL PRIMARY KEY, \ - category VARCHAR NOT NULL UNIQUE, \ - slug VARCHAR NOT NULL UNIQUE, \ - description VARCHAR NOT NULL DEFAULT '', \ - crates_cnt INTEGER NOT NULL DEFAULT 0, \ - created_at TIMESTAMP NOT NULL DEFAULT current_timestamp"), - Migration::add_table(20161115111828, "crates_categories", " \ - crate_id INTEGER NOT NULL, \ - category_id INTEGER NOT NULL"), - foreign_key(20161115111836, "crates_categories", "crate_id", "crates (id)"), - Migration::run(20161115111846, " \ - ALTER TABLE crates_categories \ - ADD CONSTRAINT fk_crates_categories_category_id \ - FOREIGN KEY (category_id) REFERENCES categories (id) \ - ON DELETE CASCADE", " \ - ALTER TABLE crates_categories \ - DROP CONSTRAINT fk_crates_categories_category_id"), - index(20161115111853, "crates_categories", "crate_id"), - index(20161115111900, "crates_categories", "category_id"), - Migration::new(20161115111957, |tx| { - tx.batch_execute(" \ - CREATE FUNCTION update_categories_crates_cnt() \ - RETURNS trigger AS $$ \ - BEGIN \ - IF (TG_OP = 'INSERT') THEN \ - UPDATE categories \ - SET crates_cnt = crates_cnt + 1 \ - WHERE id = NEW.category_id; \ - return NEW; \ - ELSIF (TG_OP = 'DELETE') THEN \ - UPDATE categories \ - SET crates_cnt = crates_cnt - 1 \ - WHERE id = OLD.category_id; \ - return OLD; \ - END IF; \ - END \ - $$ LANGUAGE plpgsql; \ - CREATE TRIGGER trigger_update_categories_crates_cnt \ - BEFORE INSERT OR DELETE \ - ON crates_categories \ - FOR EACH ROW EXECUTE PROCEDURE update_categories_crates_cnt(); \ - CREATE TRIGGER touch_crate_on_modify_categories \ - AFTER INSERT OR DELETE ON crates_categories \ - FOR EACH ROW \ - EXECUTE PROCEDURE touch_crate(); \ - ")?; - Ok(()) - }, |tx| { - tx.batch_execute(" \ - DROP TRIGGER trigger_update_categories_crates_cnt \ - ON crates_categories; \ - DROP FUNCTION update_categories_crates_cnt(); \ - DROP TRIGGER touch_crate_on_modify_categories \ - ON crates_categories;")?; - Ok(()) - }), - Migration::add_table(20170102131034, "badges", " \ - crate_id INTEGER NOT NULL, \ - badge_type VARCHAR NOT NULL, \ - attributes JSONB NOT NULL"), - Migration::new(20170102145236, |tx| { - tx.execute("CREATE UNIQUE INDEX badges_crate_type \ - ON badges (crate_id, badge_type)", &[])?; - Ok(()) - }, |tx| { - tx.execute("DROP INDEX badges_crate_type", &[])?; - Ok(()) - }), - Migration::new(20170305095748, |tx| { - tx.batch_execute(" - CREATE TABLE reserved_crate_names ( - name TEXT PRIMARY KEY - ); - CREATE UNIQUE INDEX ON reserved_crate_names (canon_crate_name(name)); - INSERT INTO reserved_crate_names (name) VALUES - ('alloc'), ('arena'), ('ast'), ('builtins'), ('collections'), - ('compiler-builtins'), ('compiler-rt'), ('compiletest'), ('core'), ('coretest'), - ('debug'), ('driver'), ('flate'), ('fmt_macros'), ('grammar'), ('graphviz'), - ('macro'), ('macros'), ('proc_macro'), ('rbml'), ('rust-installer'), ('rustbook'), - ('rustc'), ('rustc_back'), ('rustc_borrowck'), ('rustc_driver'), ('rustc_llvm'), - ('rustc_resolve'), ('rustc_trans'), ('rustc_typeck'), ('rustdoc'), ('rustllvm'), - ('rustuv'), ('serialize'), ('std'), ('syntax'), ('test'), ('unicode'); - - CREATE FUNCTION ensure_crate_name_not_reserved() RETURNS trigger AS $$ - BEGIN - IF canon_crate_name(NEW.name) IN ( - SELECT canon_crate_name(name) FROM reserved_crate_names - ) THEN - RAISE EXCEPTION 'cannot upload crate with reserved name'; - END IF; - RETURN NEW; - END; - $$ LANGUAGE plpgsql; - - CREATE TRIGGER trigger_ensure_crate_name_not_reserved - BEFORE INSERT OR UPDATE ON crates - FOR EACH ROW EXECUTE PROCEDURE ensure_crate_name_not_reserved(); - ")?; - Ok(()) - }, |tx| { - tx.execute("DROP TRIGGER trigger_ensure_crate_name_not_reserved ON crates", &[])?; - tx.execute("DROP FUNCTION ensure_crate_name_not_reserved()", &[])?; - tx.execute("DROP TABLE reserved_crate_names", &[])?; - Ok(()) - }), - ]; - // NOTE: Generate a new id via `date +"%Y%m%d%H%M%S"` - - let mut seen = HashSet::new(); - for m in migrations.iter() { - if !seen.insert(m.version()) { - panic!("duplicate id: {}", m.version()); - } - } - return migrations; +fn main() { + let _ = dotenv(); + // This code will eventually break, as it relies on internal details of Diesel. + // If this function stops working, it's probably better to just delete it. + let conn = PgConnection::establish(&env::var("DATABASE_URL").unwrap()).unwrap(); - fn foreign_key(id: i64, table: &str, column: &str, - references: &str) -> Migration { - let add = format!("ALTER TABLE {table} ADD CONSTRAINT fk_{table}_{col} - FOREIGN KEY ({col}) REFERENCES {reference}", - table = table, col = column, reference = references); - let rm = format!("ALTER TABLE {table} DROP CONSTRAINT fk_{table}_{col}", - table = table, col = column); - Migration::run(id, &add, &rm) + if !table_exists("__diesel_schema_migrations", &conn) { + setup_database(&conn).unwrap(); } - fn undo_foreign_key(id: i64, table: &str, - column: &str, - real_column: &str, - references: &str) -> Migration { - let add = format!("ALTER TABLE {table} ADD CONSTRAINT fk_{table}_{col} - FOREIGN KEY ({real_col}) REFERENCES {reference}", - table = table, col = column, reference = references, - real_col = real_column); - let rm = format!("ALTER TABLE {table} DROP CONSTRAINT fk_{table}_{col}", - table = table, col = column); - Migration::run(id, &rm, &add) + if table_exists("schema_migrations", &conn) { + conn.execute("INSERT INTO __diesel_schema_migrations ( + SELECT version::text AS version, CURRENT_TIMESTAMP as run_on + FROM schema_migrations + ) ON CONFLICT DO NOTHING").unwrap(); } - fn index(id: i64, table: &str, column: &str) -> Migration { - let add = format!("CREATE INDEX index_{table}_{column} - ON {table} ({column})", - table = table, column = column); - let rm = format!("DROP INDEX index_{table}_{column}", - table = table, column = column); - Migration::run(id, &add, &rm) - } + println!("The `migrate` binary is no longer used. Use `diesel migration run` \ + and `diesel migration revert` instead."); } -// DO NOT UPDATE OR USE FOR NEW MIGRATIONS -fn fix_duplicate_crate_owners(tx: &postgres::transaction::Transaction) -> postgres::Result<()> { - let v: Vec<(i32, i32)> = { - let stmt = tx.prepare("SELECT user_id, crate_id - FROM crate_owners - GROUP BY user_id, crate_id - HAVING COUNT(*) > 1")?; - let rows = stmt.query(&[])?; - rows.iter().map(|row| { - (row.get("user_id"), row.get("crate_id")) - }).collect() - }; - for &(user_id, crate_id) in v.iter() { - let stmt = tx.prepare("SELECT id FROM crate_owners - WHERE user_id = $1 AND crate_id = $2 - ORDER BY created_at ASC - OFFSET 1")?; - let rows = stmt.query(&[&user_id, &crate_id])?; - for row in rows.iter() { - let id: i32 = row.get("id"); - tx.execute("DELETE FROM crate_owners WHERE id = $1", &[&id])?; - } - } - Ok(()) +fn table_exists(target: &str, conn: &PgConnection) -> bool { + use self::tables::dsl::*; + use diesel::expression::dsl::exists; + + let table_query = tables.filter(table_name.eq(target)); + select(exists(table_query)).get_result(conn).unwrap() } diff --git a/src/db.rs b/src/db.rs index 1c740ccb41a..8ad2434c6fa 100644 --- a/src/db.rs +++ b/src/db.rs @@ -7,6 +7,7 @@ use std::sync::Arc; use conduit::{Request, Response}; use conduit_middleware::Middleware; +use diesel::pg::PgConnection; use openssl::ssl::{SslConnector, SslConnectorBuilder, SslMethod, SSL_VERIFY_NONE}; use pg::GenericConnection; use pg::tls::{TlsHandshake, Stream, TlsStream}; @@ -16,6 +17,8 @@ use r2d2_postgres::PostgresConnectionManager as PCM; use r2d2_postgres::TlsMode; use r2d2_postgres::postgres; use r2d2_postgres; +use r2d2_diesel::{self, ConnectionManager}; +use url::Url; use app::{App, RequestApp}; use util::{CargoResult, LazyCell, internal}; @@ -23,6 +26,8 @@ use util::{CargoResult, LazyCell, internal}; pub type Pool = r2d2::Pool; pub type Config = r2d2::Config; type PooledConnnection = r2d2::PooledConnection; +pub type DieselPool = r2d2::Pool>; +type DieselPooledConn = r2d2::PooledConnection>; /// Creates a TLS handshake mechanism used by our postgres driver to negotiate /// the TLS connection. @@ -98,6 +103,15 @@ pub fn pool(url: &str, config: r2d2::Config) -> DieselPool { + let mut url = Url::parse(url).expect("Invalid database URL"); + if env::var("HEROKU").is_ok() && !url.query_pairs().any(|(k, _)| k == "sslmode") { + url.query_pairs_mut().append_pair("sslmode", "require"); + } + let manager = ConnectionManager::new(url.into_string()); + r2d2::Pool::new(config, manager).unwrap() +} + pub struct TransactionMiddleware; pub struct Transaction { @@ -191,11 +205,20 @@ impl Middleware for TransactionMiddleware { } } +pub struct DieselMiddleware; + +impl Middleware for DieselMiddleware { + fn before(&self, request: &mut Request) -> Result<(), Box> { + request.mut_extensions().insert(LazyCell::::new()); + Ok(()) + } +} + pub trait RequestTransaction { /// Return the lazily initialized postgres connection for this request. /// /// The connection will live for the lifetime of the request. - fn db_conn(&self) -> CargoResult<&r2d2::PooledConnection>; + fn db_conn(&self) -> CargoResult<&PgConnection>; /// Return the lazily initialized postgres transaction for this request. /// @@ -203,17 +226,20 @@ pub trait RequestTransaction { /// only be set to commit() if a successful response code of 200 is seen. fn tx(&self) -> CargoResult<&GenericConnection>; - /// Flag the transaction to not be committed + /// Flag the transaction to not be committed. Does not affect Diesel connections fn rollback(&self); - /// Flag this transaction to be committed + /// Flag this transaction to be committed. Does not affect Diesel connections. fn commit(&self); } impl RequestTransaction for T { - fn db_conn(&self) -> CargoResult<&r2d2::PooledConnection> { - self.extensions().find::() - .expect("Transaction not present in request") - .conn() + fn db_conn(&self) -> CargoResult<&PgConnection> { + let cell = self.extensions().find::>() + .expect("PgConnection not present in request"); + if !cell.filled() { + cell.fill(self.app().diesel_database.get()?); + } + Ok(&**cell.borrow().unwrap()) } fn tx(&self) -> CargoResult<&GenericConnection> { diff --git a/src/lib.rs b/src/lib.rs index f3efe3fedb2..d555e19a8e2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,9 +5,12 @@ //! [user](user/index.html) and [version](version/index.html) modules. #[macro_use] extern crate log; +#[macro_use] extern crate diesel; +#[macro_use] extern crate diesel_codegen; extern crate postgres as pg; extern crate rustc_serialize; extern crate curl; +extern crate diesel_full_text_search; extern crate dotenv; extern crate flate2; extern crate git2; @@ -15,6 +18,7 @@ extern crate license_exprs; extern crate oauth2; extern crate openssl; extern crate r2d2; +extern crate r2d2_diesel; extern crate r2d2_postgres; extern crate rand; extern crate s3; @@ -63,15 +67,16 @@ pub mod dependency; pub mod dist; pub mod download; pub mod git; +pub mod http; pub mod keyword; pub mod krate; pub mod model; +pub mod owner; +pub mod schema; pub mod upload; pub mod user; -pub mod owner; pub mod util; pub mod version; -pub mod http; #[derive(PartialEq, Eq, Clone, Copy)] pub enum Env { @@ -151,6 +156,7 @@ pub fn middleware(app: Arc) -> MiddlewareBuilder { m.add(conduit_cookie::SessionMiddleware::new("cargo_session", env == Env::Production)); m.add(app::AppMiddleware::new(app)); + m.add(db::DieselMiddleware); if env != Env::Test { m.add(db::TransactionMiddleware); } diff --git a/src/schema.rs b/src/schema.rs new file mode 100644 index 00000000000..8f1eab24017 --- /dev/null +++ b/src/schema.rs @@ -0,0 +1,171 @@ +// This file can be regenerated with `diesel print-schema` + +table! { + badges (crate_id, + badge_type) { + crate_id -> Int4, + badge_type -> Varchar, + attributes -> Jsonb, + } +} + +table! { + categories (id) { + id -> Int4, + category -> Varchar, + slug -> Varchar, + description -> Varchar, + crates_cnt -> Int4, + created_at -> Timestamp, + } +} + +table! { + crate_downloads (id) { + id -> Int4, + crate_id -> Int4, + downloads -> Int4, + date -> Timestamp, + } +} + +table! { + crate_owners (id) { + id -> Int4, + crate_id -> Int4, + owner_id -> Int4, + created_at -> Timestamp, + created_by -> Nullable, + deleted -> Bool, + updated_at -> Timestamp, + owner_kind -> Int4, + } +} + +table! { + crates (id) { + id -> Int4, + name -> Varchar, + updated_at -> Timestamp, + created_at -> Timestamp, + downloads -> Int4, + max_version -> Nullable, + description -> Nullable, + homepage -> Nullable, + documentation -> Nullable, + readme -> Nullable, + textsearchable_index_col -> Nullable<::diesel_full_text_search::TsVector>, + license -> Nullable, + repository -> Nullable, + max_upload_size -> Nullable, + } +} + +table! { + crates_categories (crate_id, + category_id) { + crate_id -> Int4, + category_id -> Int4, + } +} + +table! { + crates_keywords (crate_id, + keyword_id) { + crate_id -> Int4, + keyword_id -> Int4, + } +} + +table! { + dependencies (id) { + id -> Int4, + version_id -> Int4, + crate_id -> Int4, + req -> Varchar, + optional -> Bool, + default_features -> Bool, + features -> Varchar, + target -> Nullable, + kind -> Nullable, + } +} + +table! { + follows (user_id, + crate_id) { + user_id -> Int4, + crate_id -> Int4, + } +} + +table! { + keywords (id) { + id -> Int4, + keyword -> Varchar, + crates_cnt -> Int4, + created_at -> Timestamp, + } +} + +table! { + metadata (total_downloads) { + total_downloads -> Int8, + } +} + +table! { + teams (id) { + id -> Int4, + login -> Varchar, + github_id -> Int4, + name -> Nullable, + avatar -> Nullable, + } +} + +table! { + users (id) { + id -> Int4, + email -> Nullable, + gh_access_token -> Varchar, + api_token -> Varchar, + gh_login -> Varchar, + name -> Nullable, + gh_avatar -> Nullable, + gh_id -> Int4, + } +} + +table! { + version_authors (id) { + id -> Int4, + version_id -> Int4, + user_id -> Nullable, + name -> Varchar, + } +} + +table! { + version_downloads (id) { + id -> Int4, + version_id -> Int4, + downloads -> Int4, + counted -> Int4, + date -> Timestamp, + processed -> Bool, + } +} + +table! { + versions (id) { + id -> Int4, + crate_id -> Int4, + num -> Varchar, + updated_at -> Timestamp, + created_at -> Timestamp, + downloads -> Int4, + features -> Nullable, + yanked -> Nullable, + } +} diff --git a/src/tests/all.rs b/src/tests/all.rs index 7d4acf62173..4b6cd7dda34 100755 --- a/src/tests/all.rs +++ b/src/tests/all.rs @@ -6,6 +6,7 @@ extern crate conduit; extern crate conduit_middleware; extern crate conduit_test; extern crate curl; +extern crate diesel; extern crate dotenv; extern crate git2; extern crate postgres; @@ -15,7 +16,6 @@ extern crate time; extern crate url; use std::collections::HashMap; -use std::process::Command; use std::env; use std::sync::{Once, ONCE_INIT, Arc}; use std::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; @@ -28,6 +28,8 @@ use cargo_registry::db::{self, RequestTransaction}; use cargo_registry::dependency::Kind; use cargo_registry::{User, Crate, Version, Keyword, Dependency, Category, Model}; use cargo_registry::upload as u; +use diesel::prelude::*; +use diesel::pg::PgConnection; macro_rules! t { ($e:expr) => ( @@ -96,19 +98,16 @@ fn app() -> (record::Bomb, Arc, conduit_middleware::MiddlewareBuilder) { }; INIT.call_once(|| db_setup(&config.db_url)); let app = App::new(&config); + t!(t!(app.diesel_database.get()).begin_test_transaction()); let app = Arc::new(app); let middleware = cargo_registry::middleware(app.clone()); return (bomb, app, middleware); fn db_setup(db: &str) { - let mut me = t!(env::current_exe()); - me.pop(); - if me.ends_with("deps") { - me.pop(); - } - me.push("migrate"); - assert!(t!(Command::new(&me).env("DATABASE_URL", db) - .status()).success()); + use diesel::migrations::run_pending_migrations; + + let connection = PgConnection::establish(db).unwrap(); + run_pending_migrations(&connection).unwrap(); } } diff --git a/src/tests/user.rs b/src/tests/user.rs index e10a8ddd425..76a54b66ad8 100644 --- a/src/tests/user.rs +++ b/src/tests/user.rs @@ -2,7 +2,7 @@ use conduit::{Handler, Request, Method}; use cargo_registry::Model; use cargo_registry::krate::EncodableCrate; -use cargo_registry::user::{User, EncodableUser}; +use cargo_registry::user::{User, NewUser, EncodableUser}; use cargo_registry::db::RequestTransaction; use cargo_registry::version::EncodableVersion; @@ -10,6 +10,8 @@ use cargo_registry::version::EncodableVersion; struct AuthResponse { url: String, state: String } #[derive(RustcDecodable)] struct MeResponse { user: EncodableUser, api_token: String } +#[derive(RustcDecodable)] +struct UserShowResponse { user: EncodableUser } #[test] fn auth_gives_a_token() { @@ -69,6 +71,28 @@ fn me() { assert_eq!(json.api_token, user.api_token); } +#[test] +fn show() { + let (_b, app, middle) = ::app(); + { + let conn = t!(app.diesel_database.get()); + + t!(NewUser::new(1, "foo", Some("foo@bar.com"), None, None, "bar", "baz").create_or_update(&conn)); + t!(NewUser::new(2, "bar", Some("bar@baz.com"), None, None, "bar", "baz").create_or_update(&conn)); + } + + let mut req = ::req(app.clone(), Method::Get, "/api/v1/users/foo"); + let mut response = ok_resp!(middle.call(&mut req)); + let json: UserShowResponse = ::json(&mut response); + assert_eq!(Some("foo@bar.com".into()), json.user.email); + assert_eq!("foo", json.user.login); + + let mut response = ok_resp!(middle.call(req.with_path("/api/v1/users/bar"))); + let json: UserShowResponse = ::json(&mut response); + assert_eq!(Some("bar@baz.com".into()), json.user.email); + assert_eq!("bar", json.user.login); +} + #[test] fn reset_token() { let (_b, app, middle) = ::app(); diff --git a/src/user/mod.rs b/src/user/mod.rs index 6ca3c47b84c..8980e658fbd 100644 --- a/src/user/mod.rs +++ b/src/user/mod.rs @@ -3,34 +3,94 @@ use std::collections::HashMap; use conduit::{Request, Response}; use conduit_cookie::{RequestSession}; use conduit_router::RequestParams; +use diesel::prelude::*; +use diesel::pg::PgConnection; use pg::GenericConnection; use pg::rows::Row; use rand::{thread_rng, Rng}; -use {Model, Version}; use app::RequestApp; use db::RequestTransaction; +use {http, Model, Version}; use krate::{Crate, EncodableCrate}; +use schema::users; use util::errors::NotFound; use util::{RequestUtils, CargoResult, internal, ChainError, human}; use version::EncodableVersion; -use http; pub use self::middleware::{Middleware, RequestUser}; pub mod middleware; /// The model representing a row in the `users` database table. -#[derive(Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq, Queryable)] pub struct User { pub id: i32, - pub gh_login: String, - pub gh_id: i32, - pub name: Option, pub email: Option, - pub avatar: Option, pub gh_access_token: String, pub api_token: String, + pub gh_login: String, + pub name: Option, + pub avatar: Option, + pub gh_id: i32, +} + +#[derive(Insertable, AsChangeset)] +#[table_name="users"] +pub struct NewUser<'a> { + pub gh_id: i32, + pub gh_login: &'a str, + pub email: Option<&'a str>, + pub name: Option<&'a str>, + pub gh_avatar: Option<&'a str>, + pub gh_access_token: &'a str, + pub api_token: &'a str, +} + +impl<'a> NewUser<'a> { + pub fn new(gh_id: i32, + gh_login: &'a str, + email: Option<&'a str>, + name: Option<&'a str>, + gh_avatar: Option<&'a str>, + gh_access_token: &'a str, + api_token: &'a str) -> Self { + NewUser { + gh_id: gh_id, + gh_login: gh_login, + email: email, + name: name, + gh_avatar: gh_avatar, + gh_access_token: gh_access_token, + api_token: api_token, + } + } + + /// Inserts the user into the database, or updates an existing one. + pub fn create_or_update(&self, conn: &PgConnection) -> CargoResult { + use diesel::{insert, update}; + use diesel::pg::upsert::*; + use self::users::dsl::*; + + conn.transaction(|| { + // FIXME: When Diesel 0.12 is released, this should be updated to be + // less racy. + // insert(&self.on_conflict(gh_id, do_update().set(self))) + // .into(users) + // .get_result(conn) + let maybe_inserted = insert(&self.on_conflict_do_nothing()) + .into(users) + .get_result(conn) + .optional()?; + if let Some(user) = maybe_inserted { + return Ok(user); + } + update(users.filter(gh_id.eq(self.gh_id))) + .set(self) + .get_result(conn) + .map_err(Into::into) + }) + } } /// The serialization format for the `User` model. @@ -290,15 +350,18 @@ pub fn me(req: &mut Request) -> CargoResult { /// Handles the `GET /users/:user_id` route. pub fn show(req: &mut Request) -> CargoResult { + use self::users::dsl::{users, gh_login}; + let name = &req.params()["user_id"]; - let conn = req.tx()?; - let user = User::find_by_login(conn, &name)?; + let conn = req.db_conn()?; + let user = users.filter(gh_login.eq(name)) + .first::(conn)?; #[derive(RustcEncodable)] struct R { user: EncodableUser, } - Ok(req.json(&R{ user: user.clone().encodable() })) + Ok(req.json(&R{ user: user.encodable() })) }