Skip to content

Commit

Permalink
Merge pull request #589 from sgrif/sg-port-for-real-this-time
Browse files Browse the repository at this point in the history
Set up the groundwork for a port to Diesel
  • Loading branch information
carols10cents committed Mar 7, 2017
2 parents 639ba16 + 0cdc64e commit b0a7a8d
Show file tree
Hide file tree
Showing 260 changed files with 1,091 additions and 957 deletions.
3 changes: 2 additions & 1 deletion .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
4 changes: 3 additions & 1 deletion .travis.yml
Expand Up @@ -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
Expand All @@ -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

Expand Down
138 changes: 138 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Cargo.toml
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion 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
5 changes: 4 additions & 1 deletion README.md
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions migrations/20140924113530_dumped_migration_1/down.sql
@@ -0,0 +1 @@
DROP TABLE users;
6 changes: 6 additions & 0 deletions 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
);
1 change: 1 addition & 0 deletions migrations/20140924114003_dumped_migration_2/down.sql
@@ -0,0 +1 @@
DROP TABLE packages;
5 changes: 5 additions & 0 deletions 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
);
1 change: 1 addition & 0 deletions migrations/20140924114059_dumped_migration_3/down.sql
@@ -0,0 +1 @@
DROP TABLE versions;
5 changes: 5 additions & 0 deletions 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
);
1 change: 1 addition & 0 deletions migrations/20140924115329_dumped_migration_4/down.sql
@@ -0,0 +1 @@
ALTER TABLE versions DROP CONSTRAINT unique_num;
1 change: 1 addition & 0 deletions migrations/20140924115329_dumped_migration_4/up.sql
@@ -0,0 +1 @@
ALTER TABLE versions ADD CONSTRAINT unique_num UNIQUE (package_id, num);
1 change: 1 addition & 0 deletions migrations/20140924120803_dumped_migration_5/down.sql
@@ -0,0 +1 @@
DROP TABLE version_dependencies;
4 changes: 4 additions & 0 deletions 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
);
1 change: 1 addition & 0 deletions migrations/20140925132248_dumped_migration_6/down.sql
@@ -0,0 +1 @@
ALTER TABLE packages DROP COLUMN updated_at;
1 change: 1 addition & 0 deletions migrations/20140925132248_dumped_migration_6/up.sql
@@ -0,0 +1 @@
ALTER TABLE packages ADD COLUMN updated_at TIMESTAMP NOT NULL DEFAULT now();
1 change: 1 addition & 0 deletions migrations/20140925132249_dumped_migration_7/down.sql
@@ -0,0 +1 @@
ALTER TABLE packages DROP COLUMN created_at;
1 change: 1 addition & 0 deletions migrations/20140925132249_dumped_migration_7/up.sql
@@ -0,0 +1 @@
ALTER TABLE packages ADD COLUMN created_at TIMESTAMP NOT NULL DEFAULT now();
Empty file.
2 changes: 2 additions & 0 deletions 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;
1 change: 1 addition & 0 deletions migrations/20140925132251_dumped_migration_9/down.sql
@@ -0,0 +1 @@
ALTER TABLE versions DROP COLUMN updated_at;
1 change: 1 addition & 0 deletions migrations/20140925132251_dumped_migration_9/up.sql
@@ -0,0 +1 @@
ALTER TABLE versions ADD COLUMN updated_at TIMESTAMP NOT NULL DEFAULT now();
1 change: 1 addition & 0 deletions migrations/20140925132252_dumped_migration_10/down.sql
@@ -0,0 +1 @@
ALTER TABLE versions DROP COLUMN created_at;
1 change: 1 addition & 0 deletions migrations/20140925132252_dumped_migration_10/up.sql
@@ -0,0 +1 @@
ALTER TABLE versions ADD COLUMN created_at TIMESTAMP NOT NULL DEFAULT now();
Empty file.
2 changes: 2 additions & 0 deletions 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;
Empty file.
4 changes: 4 additions & 0 deletions 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;
1 change: 1 addition & 0 deletions migrations/20140925153704_dumped_migration_13/down.sql
@@ -0,0 +1 @@
DROP TABLE metadata;
3 changes: 3 additions & 0 deletions migrations/20140925153704_dumped_migration_13/up.sql
@@ -0,0 +1,3 @@
CREATE TABLE metadata (
total_downloads BIGINT NOT NULL
);
1 change: 1 addition & 0 deletions migrations/20140925153705_dumped_migration_14/down.sql
@@ -0,0 +1 @@
DELETE FROM metadata;
1 change: 1 addition & 0 deletions migrations/20140925153705_dumped_migration_14/up.sql
@@ -0,0 +1 @@
INSERT INTO metadata (total_downloads) VALUES (0);
1 change: 1 addition & 0 deletions migrations/20140925161623_dumped_migration_15/down.sql
@@ -0,0 +1 @@
ALTER TABLE packages DROP COLUMN downloads;
1 change: 1 addition & 0 deletions migrations/20140925161623_dumped_migration_15/up.sql
@@ -0,0 +1 @@
ALTER TABLE packages ADD COLUMN downloads INTEGER NOT NULL DEFAULT 0;
1 change: 1 addition & 0 deletions migrations/20140925161624_dumped_migration_16/down.sql
@@ -0,0 +1 @@
ALTER TABLE versions DROP COLUMN downloads;
1 change: 1 addition & 0 deletions migrations/20140925161624_dumped_migration_16/up.sql
@@ -0,0 +1 @@
ALTER TABLE versions ADD COLUMN downloads INTEGER NOT NULL DEFAULT 0;
Empty file.
2 changes: 2 additions & 0 deletions 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;
1 change: 1 addition & 0 deletions migrations/20140926130044_dumped_migration_18/down.sql
@@ -0,0 +1 @@
ALTER TABLE packages DROP COLUMN max_version;
1 change: 1 addition & 0 deletions migrations/20140926130044_dumped_migration_18/up.sql
@@ -0,0 +1 @@
ALTER TABLE packages ADD COLUMN max_version VARCHAR;
1 change: 1 addition & 0 deletions migrations/20140926130046_dumped_migration_19/down.sql
@@ -0,0 +1 @@
ALTER TABLE versions ALTER COLUMN downloads DROP NOT NULL;
1 change: 1 addition & 0 deletions migrations/20140926130046_dumped_migration_19/up.sql
@@ -0,0 +1 @@
ALTER TABLE versions ALTER COLUMN downloads SET NOT NULL;
2 changes: 2 additions & 0 deletions 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;
2 changes: 2 additions & 0 deletions 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;
1 change: 1 addition & 0 deletions migrations/20140929103749_dumped_migration_21/down.sql
@@ -0,0 +1 @@
DROP INDEX index_crate_updated_at;
1 change: 1 addition & 0 deletions migrations/20140929103749_dumped_migration_21/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_crate_updated_at ON crates (updated_at);
1 change: 1 addition & 0 deletions migrations/20140929103750_dumped_migration_22/down.sql
@@ -0,0 +1 @@
DROP INDEX index_crate_created_at;
1 change: 1 addition & 0 deletions migrations/20140929103750_dumped_migration_22/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_crate_created_at ON crates (created_at);
1 change: 1 addition & 0 deletions migrations/20140929103751_dumped_migration_23/down.sql
@@ -0,0 +1 @@
DROP INDEX index_crate_downloads;
1 change: 1 addition & 0 deletions migrations/20140929103751_dumped_migration_23/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_crate_downloads ON crates (downloads);
1 change: 1 addition & 0 deletions migrations/20140929103752_dumped_migration_24/down.sql
@@ -0,0 +1 @@
DROP INDEX index_version_crate_id;
1 change: 1 addition & 0 deletions migrations/20140929103752_dumped_migration_24/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_version_crate_id ON versions (crate_id);
1 change: 1 addition & 0 deletions migrations/20140929103753_dumped_migration_25/down.sql
@@ -0,0 +1 @@
DROP INDEX index_version_num;
1 change: 1 addition & 0 deletions migrations/20140929103753_dumped_migration_25/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_version_num ON versions (num);
1 change: 1 addition & 0 deletions migrations/20140929103754_dumped_migration_26/down.sql
@@ -0,0 +1 @@
DROP INDEX index_version_dependencies_version_id;
1 change: 1 addition & 0 deletions migrations/20140929103754_dumped_migration_26/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_version_dependencies_version_id ON version_dependencies (version_id);
1 change: 1 addition & 0 deletions migrations/20140929103755_dumped_migration_27/down.sql
@@ -0,0 +1 @@
DROP INDEX index_version_dependencies_depends_on_id;
1 change: 1 addition & 0 deletions migrations/20140929103755_dumped_migration_27/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_version_dependencies_depends_on_id ON version_dependencies (depends_on_id);
1 change: 1 addition & 0 deletions migrations/20140929103756_dumped_migration_28/down.sql
@@ -0,0 +1 @@
DROP TABLE crate_downloads;
6 changes: 6 additions & 0 deletions 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
);
1 change: 1 addition & 0 deletions migrations/20140929103757_dumped_migration_29/down.sql
@@ -0,0 +1 @@
DROP INDEX index_crate_downloads_crate_id;
1 change: 1 addition & 0 deletions migrations/20140929103757_dumped_migration_29/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_crate_downloads_crate_id ON crate_downloads (crate_id);
1 change: 1 addition & 0 deletions migrations/20140929103758_dumped_migration_30/down.sql
@@ -0,0 +1 @@
DROP INDEX index_crate_downloads_date;
1 change: 1 addition & 0 deletions migrations/20140929103758_dumped_migration_30/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_crate_downloads_date ON crate_downloads (date(date));
1 change: 1 addition & 0 deletions migrations/20140929103759_dumped_migration_31/down.sql
@@ -0,0 +1 @@
DROP TABLE version_downloads;
8 changes: 8 additions & 0 deletions 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
);
1 change: 1 addition & 0 deletions migrations/20140929103760_dumped_migration_32/down.sql
@@ -0,0 +1 @@
DROP INDEX index_version_downloads_version_id;
1 change: 1 addition & 0 deletions migrations/20140929103760_dumped_migration_32/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_version_downloads_version_id ON version_downloads (version_id);
1 change: 1 addition & 0 deletions migrations/20140929103761_dumped_migration_33/down.sql
@@ -0,0 +1 @@
DROP INDEX index_version_downloads_date;
1 change: 1 addition & 0 deletions migrations/20140929103761_dumped_migration_33/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_version_downloads_date ON version_downloads (date(date));
1 change: 1 addition & 0 deletions migrations/20140929103763_dumped_migration_34/down.sql
@@ -0,0 +1 @@
DROP INDEX index_version_downloads_processed;
2 changes: 2 additions & 0 deletions migrations/20140929103763_dumped_migration_34/up.sql
@@ -0,0 +1,2 @@
CREATE INDEX index_version_downloads_processed ON version_downloads (processed)
WHERE processed = FALSE;
1 change: 1 addition & 0 deletions migrations/20140929185718_dumped_migration_35/down.sql
@@ -0,0 +1 @@
DROP INDEX index_crates_name_search;
1 change: 1 addition & 0 deletions migrations/20140929185718_dumped_migration_35/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_crates_name_search ON crates USING gin(to_tsvector('english', name));
3 changes: 3 additions & 0 deletions migrations/20140930082104_dumped_migration_36/down.sql
@@ -0,0 +1,3 @@
CREATE TABLE version_dependencies (
version_id INTEGER
);
1 change: 1 addition & 0 deletions migrations/20140930082104_dumped_migration_36/up.sql
@@ -0,0 +1 @@
DROP TABLE version_dependencies;
1 change: 1 addition & 0 deletions migrations/20140930082105_dumped_migration_37/down.sql
@@ -0,0 +1 @@
DROP TABLE dependencies;
9 changes: 9 additions & 0 deletions 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
);
1 change: 1 addition & 0 deletions migrations/20140930085441_dumped_migration_38/down.sql
@@ -0,0 +1 @@
ALTER TABLE versions DROP COLUMN features;
1 change: 1 addition & 0 deletions migrations/20140930085441_dumped_migration_38/up.sql
@@ -0,0 +1 @@
ALTER TABLE versions ADD COLUMN features VARCHAR;
1 change: 1 addition & 0 deletions migrations/20140930203145_dumped_migration_39/down.sql
@@ -0,0 +1 @@
DROP INDEX index_dependencies_version_id;
1 change: 1 addition & 0 deletions migrations/20140930203145_dumped_migration_39/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_dependencies_version_id ON dependencies (version_id);
1 change: 1 addition & 0 deletions migrations/20140930203146_dumped_migration_40/down.sql
@@ -0,0 +1 @@
DROP INDEX index_dependencies_crate_id;
1 change: 1 addition & 0 deletions migrations/20140930203146_dumped_migration_40/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_dependencies_crate_id ON dependencies (crate_id);
1 change: 1 addition & 0 deletions migrations/20141001190227_dumped_migration_41/down.sql
@@ -0,0 +1 @@
ALTER TABLE users DROP COLUMN gh_login;
1 change: 1 addition & 0 deletions migrations/20141001190227_dumped_migration_41/up.sql
@@ -0,0 +1 @@
ALTER TABLE users ADD COLUMN gh_login VARCHAR NOT NULL;
1 change: 1 addition & 0 deletions migrations/20141001190228_dumped_migration_42/down.sql
@@ -0,0 +1 @@
ALTER TABLE users DROP COLUMN name;
1 change: 1 addition & 0 deletions migrations/20141001190228_dumped_migration_42/up.sql
@@ -0,0 +1 @@
ALTER TABLE users ADD COLUMN name VARCHAR;
1 change: 1 addition & 0 deletions migrations/20141001190229_dumped_migration_43/down.sql
@@ -0,0 +1 @@
DROP INDEX index_users_gh_login;
1 change: 1 addition & 0 deletions migrations/20141001190229_dumped_migration_43/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_users_gh_login ON users (gh_login);
1 change: 1 addition & 0 deletions migrations/20141001190230_dumped_migration_44/down.sql
@@ -0,0 +1 @@
ALTER TABLE users ALTER COLUMN email SET NOT NULL;
1 change: 1 addition & 0 deletions migrations/20141001190230_dumped_migration_44/up.sql
@@ -0,0 +1 @@
ALTER TABLE users ALTER COLUMN email DROP NOT NULL;
1 change: 1 addition & 0 deletions migrations/20141001190231_dumped_migration_45/down.sql
@@ -0,0 +1 @@
ALTER TABLE users DROP COLUMN gh_avatar;
1 change: 1 addition & 0 deletions migrations/20141001190231_dumped_migration_45/up.sql
@@ -0,0 +1 @@
ALTER TABLE users ADD COLUMN gh_avatar VARCHAR;
1 change: 1 addition & 0 deletions migrations/20141002195939_dumped_migration_46/down.sql
@@ -0,0 +1 @@
DROP INDEX index_crates_user_id;
1 change: 1 addition & 0 deletions migrations/20141002195939_dumped_migration_46/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_crates_user_id ON crates (user_id);
1 change: 1 addition & 0 deletions migrations/20141002195940_dumped_migration_47/down.sql
@@ -0,0 +1 @@
DROP TABLE follows;
4 changes: 4 additions & 0 deletions migrations/20141002195940_dumped_migration_47/up.sql
@@ -0,0 +1,4 @@
CREATE TABLE follows (
user_id INTEGER NOT NULL,
crate_id INTEGER NOT NULL
);
1 change: 1 addition & 0 deletions migrations/20141002195941_dumped_migration_48/down.sql
@@ -0,0 +1 @@
DROP INDEX index_follows_user_id;
1 change: 1 addition & 0 deletions migrations/20141002195941_dumped_migration_48/up.sql
@@ -0,0 +1 @@
CREATE INDEX index_follows_user_id ON follows (user_id);
1 change: 1 addition & 0 deletions migrations/20141002222426_dumped_migration_49/down.sql
@@ -0,0 +1 @@
ALTER TABLE crate_downloads DROP CONSTRAINT fk_crate_downloads_crate_id;
2 changes: 2 additions & 0 deletions 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);
1 change: 1 addition & 0 deletions migrations/20141002222427_dumped_migration_50/down.sql
@@ -0,0 +1 @@
ALTER TABLE crates DROP CONSTRAINT fk_crates_user_id;

0 comments on commit b0a7a8d

Please sign in to comment.