diff --git a/.travis.yml b/.travis.yml index 45399b5c5..e22e23be2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,8 +7,8 @@ go: env: global: - PATH=${PATH}:./bin - - POP_PATH=$PWD/cmd/proxy - - GO_ENV=test_postgres + - POP_PATH=$PWD/cmd/olympus + - GO_ENV=test - MINIO_ACCESS_KEY=minio - MINIO_SECRET_KEY=minio123 - ATHENS_MONGO_CONNECTION_STRING=mongodb://127.0.0.1:27017 @@ -20,8 +20,9 @@ before_script: - make setup-dev-env - wget "https://dl.minio.io/server/minio/release/linux-amd64/minio" - chmod +x minio && nohup ./minio server . & - - buffalo db create - - buffalo db migrate up + - buffalo db create -e $GO_ENV -d -c $POP_PATH/database.yml + - buffalo db migrate up -e $GO_ENV -d -c $POP_PATH/database.yml + script: - make verify test-unit test-e2e diff --git a/Makefile b/Makefile index 67e1c9562..c9700eb86 100644 --- a/Makefile +++ b/Makefile @@ -51,7 +51,6 @@ bench: .PHONY: alldeps alldeps: - docker-compose -p athensdev up -d mysql docker-compose -p athensdev up -d postgres docker-compose -p athensdev up -d mongo docker-compose -p athensdev up -d redis diff --git a/cmd/olympus/actions/app.go b/cmd/olympus/actions/app.go index b0fa0c203..ba6899d2c 100644 --- a/cmd/olympus/actions/app.go +++ b/cmd/olympus/actions/app.go @@ -109,11 +109,6 @@ func App(config *AppConfig) (*buffalo.App, error) { // TODO: initialize the azurecdn.Storage struct here })) - // Wraps each request in a transaction. - // c.Value("tx").(*pop.PopTransaction) - // Remove to disable this. - // app.Use(middleware.PopTransaction(models.DB)) - // Setup and use translations: if T, err = i18n.New(packr.NewBox("../locales"), "en-US"); err != nil { app.Stop(err) diff --git a/cmd/olympus/actions/storage.go b/cmd/olympus/actions/storage.go index 9d01eb4fa..0d2e2947b 100644 --- a/cmd/olympus/actions/storage.go +++ b/cmd/olympus/actions/storage.go @@ -8,7 +8,6 @@ import ( "github.com/gomods/athens/pkg/storage/fs" "github.com/gomods/athens/pkg/storage/mem" "github.com/gomods/athens/pkg/storage/mongo" - "github.com/gomods/athens/pkg/storage/rdbms" "github.com/spf13/afero" ) @@ -35,12 +34,6 @@ func GetStorage() (storage.Backend, error) { } certPath := env.MongoCertPath() return mongo.NewStorageWithCert(connectionString, certPath) - case "postgres", "sqlite", "cockroach", "mysql": - connectionName, err := env.RdbmsName() - if err != nil { - return nil, err - } - return rdbms.NewRDBMSStorage(connectionName) default: return nil, fmt.Errorf("storage type %s is unknown", storageType) } diff --git a/cmd/olympus/database.yml b/cmd/olympus/database.yml index 59a5ad386..1ea95019f 100644 --- a/cmd/olympus/database.yml +++ b/cmd/olympus/database.yml @@ -1,29 +1,22 @@ development: - dialect: "mysql" + dialect: "postgres" database: athens host: 127.0.0.1 - port: 3306 - user: vgp - password: vgp + port: 5432 + user: postgres + password: postgres -test_postgres: +test: dialect: "postgres" - database: athens_development + database: athens_test user: postgres - password: '' + password: postgres + port: 5432 host: 127.0.0.1 pool: 5 -test: - dialect: "mysql" - database: athens - host: 127.0.0.1 - port: 3306 - user: vgp - password: vgp - production: - dialect: "mysql" + dialect: "postgres" database: olympusdb host: {{ env "DB_HOST" }} port: {{ env "DB_PORT" }} diff --git a/cmd/olympus/migrations/schema.sql b/cmd/olympus/migrations/schema.sql index 38587bec3..5121d2244 100644 --- a/cmd/olympus/migrations/schema.sql +++ b/cmd/olympus/migrations/schema.sql @@ -1,40 +1,57 @@ --- MySQL dump 10.13 Distrib 5.7.21, for osx10.13 (x86_64) --- --- Host: 127.0.0.1 Database: athens --- ------------------------------------------------------ --- Server version 5.7.21 - -/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; -/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; -/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; -/*!40101 SET NAMES utf8 */; -/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; -/*!40103 SET TIME_ZONE='+00:00' */; -/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; -/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; -/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; -/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; - --- --- Table structure for table `schema_migration` --- - -DROP TABLE IF EXISTS `schema_migration`; -/*!40101 SET @saved_cs_client = @@character_set_client */; -/*!40101 SET character_set_client = utf8 */; -CREATE TABLE `schema_migration` ( - `version` varchar(255) NOT NULL, - UNIQUE KEY `version_idx` (`version`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8; -/*!40101 SET character_set_client = @saved_cs_client */; -/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; - -/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; -/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; -/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; -/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; -/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; -/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; -/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; - --- Dump completed on 2018-06-06 12:42:59 +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 9.6.9 +-- Dumped by pg_dump version 10.4 + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET client_min_messages = warning; +SET row_security = off; + +-- +-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: +-- + +CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; + + +-- +-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; + + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Name: schema_migration; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.schema_migration ( + version character varying(255) NOT NULL +); + + +ALTER TABLE public.schema_migration OWNER TO postgres; + +-- +-- Name: schema_migration_version_idx; Type: INDEX; Schema: public; Owner: postgres +-- + +CREATE UNIQUE INDEX schema_migration_version_idx ON public.schema_migration USING btree (version); + + +-- +-- PostgreSQL database dump complete +-- + diff --git a/cmd/olympus/models/models.go b/cmd/olympus/models/models.go index 83ef8c4b0..8b048441a 100644 --- a/cmd/olympus/models/models.go +++ b/cmd/olympus/models/models.go @@ -1,22 +1,5 @@ package models -import ( - "log" - - "github.com/gobuffalo/pop" - "github.com/gomods/athens/pkg/config/env" -) - -// DB is a connection to your database to be used -// throughout your application. -var DB *pop.Connection - func init() { - var err error - env := env.GoEnvironmentWithDefault("development") - DB, err = pop.Connect(env) - if err != nil { - log.Fatal(err) - } - pop.Debug = env == "development" + } diff --git a/cmd/olympus/models/models_test.go b/cmd/olympus/models/models_test.go index dc85367f7..f2756b88b 100644 --- a/cmd/olympus/models/models_test.go +++ b/cmd/olympus/models/models_test.go @@ -2,15 +2,8 @@ package models_test import ( "testing" - - "github.com/gobuffalo/suite" ) -type ModelSuite struct { - *suite.Model -} - func Test_ModelSuite(t *testing.T) { - as := &ModelSuite{suite.NewModel()} - suite.Run(t, as) + } diff --git a/cmd/proxy/actions/app.go b/cmd/proxy/actions/app.go index 26d12e68e..4caf583d3 100644 --- a/cmd/proxy/actions/app.go +++ b/cmd/proxy/actions/app.go @@ -119,12 +119,6 @@ func App() (*buffalo.App, error) { csrfMiddleware := csrf.New app.Use(csrfMiddleware) } - - // Wraps each request in a transaction. - // c.Value("tx").(*pop.PopTransaction) - // Remove to disable this. - // app.Use(middleware.PopTransaction(models.DB)) - // Setup and use translations: if T, err = i18n.New(packr.NewBox("../locales"), "en-US"); err != nil { app.Stop(err) diff --git a/cmd/proxy/actions/storage.go b/cmd/proxy/actions/storage.go index 8d44592ab..0be621352 100644 --- a/cmd/proxy/actions/storage.go +++ b/cmd/proxy/actions/storage.go @@ -12,7 +12,6 @@ import ( "github.com/gomods/athens/pkg/storage/mem" "github.com/gomods/athens/pkg/storage/minio" "github.com/gomods/athens/pkg/storage/mongo" - "github.com/gomods/athens/pkg/storage/rdbms" "github.com/spf13/afero" ) @@ -43,12 +42,6 @@ func GetStorage() (storage.Backend, error) { return nil, fmt.Errorf("could not create new storage from os fs (%s)", err) } return s, nil - case "postgres", "sqlite", "cockroach", "mysql": - storageRoot, err = env.RdbmsName() - if err != nil { - return nil, err - } - return rdbms.NewRDBMSStorage(storageRoot) case "minio": endpoint, err := env.MinioEndpoint() if err != nil { diff --git a/cmd/proxy/database.yml b/cmd/proxy/database.yml deleted file mode 100644 index 4369e901c..000000000 --- a/cmd/proxy/database.yml +++ /dev/null @@ -1,31 +0,0 @@ -development: - dialect: "mysql" - database: athens - host: 127.0.0.1 - port: 3306 - user: vgp - password: vgp - -test: - dialect: "mysql" - database: athens - host: 127.0.0.1 - port: 3306 - user: vgp - password: vgp - -test_postgres: - dialect: "postgres" - database: athens_development - user: postgres - password: '' - host: 127.0.0.1 - pool: 5 - -production: - dialect: "mysql" - database: olympusdb - host: {{ env "DB_HOST" }} - port: {{ env "DB_PORT" }} - user: {{ env "DB_USER" }} - password: {{ env "DB_PASS" }} diff --git a/cmd/proxy/models/models.go b/cmd/proxy/models/models.go deleted file mode 100644 index 83ef8c4b0..000000000 --- a/cmd/proxy/models/models.go +++ /dev/null @@ -1,22 +0,0 @@ -package models - -import ( - "log" - - "github.com/gobuffalo/pop" - "github.com/gomods/athens/pkg/config/env" -) - -// DB is a connection to your database to be used -// throughout your application. -var DB *pop.Connection - -func init() { - var err error - env := env.GoEnvironmentWithDefault("development") - DB, err = pop.Connect(env) - if err != nil { - log.Fatal(err) - } - pop.Debug = env == "development" -} diff --git a/cmd/proxy/models/models_test.go b/cmd/proxy/models/models_test.go deleted file mode 100644 index dc85367f7..000000000 --- a/cmd/proxy/models/models_test.go +++ /dev/null @@ -1,16 +0,0 @@ -package models_test - -import ( - "testing" - - "github.com/gobuffalo/suite" -) - -type ModelSuite struct { - *suite.Model -} - -func Test_ModelSuite(t *testing.T) { - as := &ModelSuite{suite.NewModel()} - suite.Run(t, as) -} diff --git a/docker-compose.yml b/docker-compose.yml index 2235f179c..83b46d68b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,19 +9,13 @@ services: image: mongo:3.7.9-jessie ports: - 27017:27017 - mysql: - image: bitnami/mysql:5.7.21-r7 - ports: - - "3306:3306" - environment: - - "ALLOW_EMPTY_PASSWORD=yes" - - "MYSQL_USER=vgp" - - "MYSQL_PASSWORD=vgp" - - "MYSQL_DATABASE=athens" postgres: image: postgres:9.6.9-alpine ports: - "5432:5432" + environment: + POSTGRES_USER: postgres + POSTGRES_PASSWORD: postgres minio: image: minio/minio:latest command: server /data diff --git a/migrations/schema.sql b/migrations/schema.sql index e69de29bb..74f0bdd46 100644 --- a/migrations/schema.sql +++ b/migrations/schema.sql @@ -0,0 +1,106 @@ +-- +-- PostgreSQL database dump +-- + +-- Dumped from database version 9.6.9 +-- Dumped by pg_dump version 10.4 + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET client_min_messages = warning; +SET row_security = off; + +-- +-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: +-- + +CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog; + + +-- +-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: +-- + +COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language'; + + +SET default_tablespace = ''; + +SET default_with_oids = false; + +-- +-- Name: cdn_metadata_entries; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.cdn_metadata_entries ( + id uuid NOT NULL, + module text NOT NULL, + redirect_url text NOT NULL, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL +); + + +ALTER TABLE public.cdn_metadata_entries OWNER TO postgres; + +-- +-- Name: modules; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.modules ( + id uuid NOT NULL, + module text NOT NULL, + version text NOT NULL, + mod bytea NOT NULL, + zip bytea NOT NULL, + info bytea NOT NULL, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL +); + + +ALTER TABLE public.modules OWNER TO postgres; + +-- +-- Name: schema_migration; Type: TABLE; Schema: public; Owner: postgres +-- + +CREATE TABLE public.schema_migration ( + version character varying(255) NOT NULL +); + + +ALTER TABLE public.schema_migration OWNER TO postgres; + +-- +-- Name: cdn_metadata_entries cdn_metadata_entries_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.cdn_metadata_entries + ADD CONSTRAINT cdn_metadata_entries_pkey PRIMARY KEY (id); + + +-- +-- Name: modules modules_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.modules + ADD CONSTRAINT modules_pkey PRIMARY KEY (id); + + +-- +-- Name: schema_migration_version_idx; Type: INDEX; Schema: public; Owner: postgres +-- + +CREATE UNIQUE INDEX schema_migration_version_idx ON public.schema_migration USING btree (version); + + +-- +-- PostgreSQL database dump complete +-- + diff --git a/pkg/cdn/metadata/cdn_metadata_entry.go b/pkg/cdn/metadata/cdn_metadata_entry.go index fac16a8a8..5db7057ba 100644 --- a/pkg/cdn/metadata/cdn_metadata_entry.go +++ b/pkg/cdn/metadata/cdn_metadata_entry.go @@ -1,13 +1,9 @@ package metadata import ( - "encoding/json" "time" - "github.com/gobuffalo/pop" "github.com/gobuffalo/uuid" - "github.com/gobuffalo/validate" - "github.com/gobuffalo/validate/validators" ) // CDNMetadataEntry stores the module name and cdn URL. @@ -19,36 +15,6 @@ type CDNMetadataEntry struct { RedirectURL string `json:"redirect_url" db:"redirect_url" bson:"redirect_url"` } -// String is not required by pop and may be deleted -func (e CDNMetadataEntry) String() string { - je, _ := json.Marshal(e) - return string(je) -} - -// CdnMetadataEntries is not required by pop and may be deleted -type CdnMetadataEntries []CDNMetadataEntry - -// Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method. -// This method is not required and may be deleted. -func (e *CDNMetadataEntry) Validate(tx *pop.Connection) (*validate.Errors, error) { - return validate.Validate( - &validators.StringIsPresent{Field: e.Module, Name: "Module"}, - &validators.StringIsPresent{Field: e.RedirectURL, Name: "RedirectURL"}, - ), nil -} - -// ValidateCreate gets run every time you call "pop.ValidateAndCreate" method. -// This method is not required and may be deleted. -func (e *CDNMetadataEntry) ValidateCreate(tx *pop.Connection) (*validate.Errors, error) { - return validate.NewErrors(), nil -} - -// ValidateUpdate gets run every time you call "pop.ValidateAndUpdate" method. -// This method is not required and may be deleted. -func (e *CDNMetadataEntry) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error) { - return validate.NewErrors(), nil -} - // TableName changes the default name which would be c_d_n_metadata_entry func (e *CDNMetadataEntry) TableName() string { return "cdn_metadata_entries" diff --git a/pkg/cdn/metadata/rdbms/rdbms_test.go b/pkg/cdn/metadata/rdbms/rdbms_test.go index 833cdbae5..c843d02de 100644 --- a/pkg/cdn/metadata/rdbms/rdbms_test.go +++ b/pkg/cdn/metadata/rdbms/rdbms_test.go @@ -1,5 +1,9 @@ package rdbms +import ( + "github.com/gobuffalo/envy" +) + func (rd *RDBMSTestSuite) TestGetSaveRoundTrip() { r := rd.Require() err := rd.storage.Save(module, redirectURL) @@ -12,7 +16,7 @@ func (rd *RDBMSTestSuite) TestGetSaveRoundTrip() { func (rd *RDBMSTestSuite) TestNewRDBMSStorage() { r := rd.Require() - e := "development" + e := envy.Get("GO_ENV", "test") getterSaver := NewStorage(e) getterSaver.Connect() diff --git a/pkg/storage/rdbms/all_test.go b/pkg/storage/rdbms/all_test.go deleted file mode 100644 index 1d143775e..000000000 --- a/pkg/storage/rdbms/all_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package rdbms - -import ( - "testing" - - "github.com/gobuffalo/suite" - "github.com/gomods/athens/pkg/storage" -) - -type RDBMSTestSuite struct { - *suite.Model - storage storage.Backend -} - -func (rd *RDBMSTestSuite) SetupTest() { - rd.storage = &ModuleStore{conn: rd.DB} - rd.Model.SetupTest() -} - -func Test_ActionSuite(t *testing.T) { - suite.Run(t, &RDBMSTestSuite{Model: suite.NewModel()}) -} diff --git a/pkg/storage/rdbms/checker.go b/pkg/storage/rdbms/checker.go deleted file mode 100644 index 7608709ca..000000000 --- a/pkg/storage/rdbms/checker.go +++ /dev/null @@ -1,19 +0,0 @@ -package rdbms - -import ( - "context" - - "github.com/gomods/athens/pkg/storage/rdbms/models" - opentracing "github.com/opentracing/opentracing-go" -) - -// Exists checks for a specific version of a module -func (r *ModuleStore) Exists(ctx context.Context, module, vsn string) bool { - sp, ctx := opentracing.StartSpanFromContext(ctx, "storage.rdbms.Exists") - defer sp.Finish() - result := models.Module{} - query := r.conn.Where("module = ?", module).Where("version = ?", vsn) - count, err := query.Count(&result) - - return err == nil && count > 0 -} diff --git a/pkg/storage/rdbms/deleter.go b/pkg/storage/rdbms/deleter.go deleted file mode 100644 index d7ce45bea..000000000 --- a/pkg/storage/rdbms/deleter.go +++ /dev/null @@ -1,25 +0,0 @@ -package rdbms - -import ( - "context" - - "github.com/gomods/athens/pkg/errors" - "github.com/gomods/athens/pkg/storage/rdbms/models" - opentracing "github.com/opentracing/opentracing-go" -) - -// Delete removes a specific version of a module. -func (r *ModuleStore) Delete(ctx context.Context, module, version string) error { - const op errors.Op = "rdbms.Delete" - sp, ctx := opentracing.StartSpanFromContext(ctx, "storage.rdbms.Delete") - defer sp.Finish() - if !r.Exists(ctx, module, version) { - return errors.E(op, errors.M(module), errors.V(version), errors.KindNotFound) - } - result := &models.Module{} - query := r.conn.Where("module = ?", module).Where("version = ?", version) - if err := query.First(result); err != nil { - return errors.E(op, err) - } - return r.conn.Destroy(result) -} diff --git a/pkg/storage/rdbms/getter.go b/pkg/storage/rdbms/getter.go deleted file mode 100644 index c68841741..000000000 --- a/pkg/storage/rdbms/getter.go +++ /dev/null @@ -1,50 +0,0 @@ -package rdbms - -import ( - "bytes" - "context" - "database/sql" - "io" - "io/ioutil" - - "github.com/gomods/athens/pkg/errors" - "github.com/gomods/athens/pkg/storage" - "github.com/gomods/athens/pkg/storage/rdbms/models" - opentracing "github.com/opentracing/opentracing-go" - pkgerrors "github.com/pkg/errors" -) - -// Get a specific version of a module -func (r *ModuleStore) Get(ctx context.Context, module, vsn string) (*storage.Version, error) { - const op errors.Op = "rdbms.Get" - sp, ctx := opentracing.StartSpanFromContext(ctx, "storage.rdbms.Get") - defer sp.Finish() - result := models.Module{} - query := r.conn.Where("module = ?", module).Where("version = ?", vsn) - if err := query.First(&result); err != nil { - if pkgerrors.Cause(err) == sql.ErrNoRows { // can we just say err == sql.ErrNoRows? - return nil, errors.E(op, errors.M(module), errors.V(vsn), errors.KindNotFound) - } - return nil, errors.E(op, err) - } - return &storage.Version{ - Mod: result.Mod, - Zip: ioutil.NopCloser(bytes.NewReader(result.Zip)), - Info: result.Info, - }, nil -} - -// Info will panic. -func (r *ModuleStore) Info(ctx context.Context, module, vsn string) ([]byte, error) { - panic("") -} - -// GoMod will panic. -func (r *ModuleStore) GoMod(ctx context.Context, module, vsn string) ([]byte, error) { - panic("") -} - -// Zip will panic. -func (r *ModuleStore) Zip(ctx context.Context, module, vsn string) (io.ReadCloser, error) { - panic("") -} diff --git a/pkg/storage/rdbms/lister.go b/pkg/storage/rdbms/lister.go deleted file mode 100644 index d959d2670..000000000 --- a/pkg/storage/rdbms/lister.go +++ /dev/null @@ -1,26 +0,0 @@ -package rdbms - -import ( - "context" - - "github.com/gomods/athens/pkg/storage/rdbms/models" - opentracing "github.com/opentracing/opentracing-go" -) - -// List lists all versions of a module -func (r *ModuleStore) List(ctx context.Context, module string) ([]string, error) { - sp, ctx := opentracing.StartSpanFromContext(ctx, "storage.rdbms.List") - defer sp.Finish() - result := make([]models.Module, 0) - err := r.conn.Where("module = ?", module).All(&result) - if err != nil { - return nil, err - } - - versions := make([]string, len(result)) - for i := range result { - versions[i] = result[i].Version - } - - return versions, nil -} diff --git a/pkg/storage/rdbms/models/modules.go b/pkg/storage/rdbms/models/modules.go deleted file mode 100644 index 6f187054f..000000000 --- a/pkg/storage/rdbms/models/modules.go +++ /dev/null @@ -1,62 +0,0 @@ -package models - -import ( - "encoding/json" - "time" - - "github.com/gobuffalo/pop" - "github.com/gobuffalo/uuid" - "github.com/gobuffalo/validate" - "github.com/gobuffalo/validate/validators" -) - -// Module is a model where data is stored. -type Module struct { - ID uuid.UUID `json:"id" db:"id"` - CreatedAt time.Time `json:"created_at" db:"created_at"` - UpdatedAt time.Time `json:"updated_at" db:"updated_at"` - Module string `json:"module" db:"module"` - Version string `json:"version" db:"version"` - Mod []byte `json:"mod" db:"mod"` - Zip []byte `json:"zip" db:"zip"` - Info []byte `json:"info" db:"info"` -} - -// String is not required by pop and may be deleted -func (m Module) String() string { - jm, _ := json.Marshal(m) - return string(jm) -} - -// Modules is not required by pop and may be deleted -type Modules []Module - -// String is not required by pop and may be deleted -func (m Modules) String() string { - jm, _ := json.Marshal(m) - return string(jm) -} - -// Validate gets run every time you call a "pop.Validate*" (pop.ValidateAndSave, pop.ValidateAndCreate, pop.ValidateAndUpdate) method. -// This method is not required and may be deleted. -func (m *Module) Validate(tx *pop.Connection) (*validate.Errors, error) { - return validate.Validate( - &validators.StringIsPresent{Field: m.Module, Name: "Module"}, - &validators.StringIsPresent{Field: m.Version, Name: "Version"}, - &validators.BytesArePresent{Field: m.Mod, Name: "Mod"}, - &validators.BytesArePresent{Field: m.Zip, Name: "Zip"}, - &validators.BytesArePresent{Field: m.Info, Name: "Info"}, - ), nil -} - -// ValidateCreate gets run every time you call "pop.ValidateAndCreate" method. -// This method is not required and may be deleted. -func (m *Module) ValidateCreate(tx *pop.Connection) (*validate.Errors, error) { - return validate.NewErrors(), nil -} - -// ValidateUpdate gets run every time you call "pop.ValidateAndUpdate" method. -// This method is not required and may be deleted. -func (m *Module) ValidateUpdate(tx *pop.Connection) (*validate.Errors, error) { - return validate.NewErrors(), nil -} diff --git a/pkg/storage/rdbms/rdbms.go b/pkg/storage/rdbms/rdbms.go deleted file mode 100644 index 816982c23..000000000 --- a/pkg/storage/rdbms/rdbms.go +++ /dev/null @@ -1,45 +0,0 @@ -package rdbms - -import ( - "github.com/gobuffalo/pop" - "github.com/gomods/athens/pkg/errors" -) - -// ModuleStore represents a rdbms(postgres, mysql, sqlite, cockroachdb) backed storage backend. -type ModuleStore struct { - conn *pop.Connection - connectionName string // settings name from database.yml -} - -// NewRDBMSStorage returns a connected RDBMS Module Storage -// that satisfies the Storage interface. -func NewRDBMSStorage(connectionName string) (*ModuleStore, error) { - const op errors.Op = "rdbms.NewRDBMSStorage" - - ms := &ModuleStore{ - connectionName: connectionName, - } - err := ms.connect() - if err != nil { - return nil, errors.E(op, err) - } - return ms, nil -} - -// NewRDBMSStorageWithConn returns a connected RDBMS Module Storage -// that satisfies the Storage interface. -func NewRDBMSStorageWithConn(connection *pop.Connection) *ModuleStore { - ms := &ModuleStore{ - conn: connection, - } - return ms -} - -func (r *ModuleStore) connect() error { - c, err := pop.Connect(r.connectionName) - if err != nil { - return err - } - r.conn = c - return nil -} diff --git a/pkg/storage/rdbms/rdbms_test.go b/pkg/storage/rdbms/rdbms_test.go deleted file mode 100644 index 34d11652f..000000000 --- a/pkg/storage/rdbms/rdbms_test.go +++ /dev/null @@ -1,11 +0,0 @@ -package rdbms - -func (rd *RDBMSTestSuite) TestNewRDBMSStorage() { - r := rd.Require() - e := "development" - getterSaver, err := NewRDBMSStorage(e) - r.NoError(err) - - r.NotNil(getterSaver.conn) - r.Equal(getterSaver.connectionName, e) -} diff --git a/pkg/storage/rdbms/saver.go b/pkg/storage/rdbms/saver.go deleted file mode 100644 index 0c582c08c..000000000 --- a/pkg/storage/rdbms/saver.go +++ /dev/null @@ -1,29 +0,0 @@ -package rdbms - -import ( - "context" - "io" - "io/ioutil" - - "github.com/gomods/athens/pkg/storage/rdbms/models" - opentracing "github.com/opentracing/opentracing-go" -) - -// Save stores a module in rdbms storage. -func (r *ModuleStore) Save(ctx context.Context, module, version string, mod []byte, zip io.Reader, info []byte) error { - sp, ctx := opentracing.StartSpanFromContext(ctx, "storage.rdbms.Save") - defer sp.Finish() - zipBytes, err := ioutil.ReadAll(zip) - if err != nil { - return err - } - m := &models.Module{ - Module: module, - Version: version, - Mod: mod, - Zip: zipBytes, - Info: info, - } - - return r.conn.Create(m) -} diff --git a/pkg/storage/rdbms/test_suite.go b/pkg/storage/rdbms/test_suite.go deleted file mode 100644 index 5bd5333c7..000000000 --- a/pkg/storage/rdbms/test_suite.go +++ /dev/null @@ -1,38 +0,0 @@ -package rdbms - -import ( - "github.com/gobuffalo/suite" - "github.com/gomods/athens/pkg/storage" -) - -// TestSuite implements TestSuite interface -type TestSuite struct { - *suite.Model - storage storage.Backend -} - -// NewTestSuite creates a common test suite -func NewTestSuite(model *suite.Model) (storage.TestSuite, error) { - conn := model.DB - rdbmsStore := NewRDBMSStorageWithConn(conn) - - return &TestSuite{ - storage: rdbmsStore, - Model: model, - }, nil -} - -// Storage retrieves initialized storage backend -func (ts *TestSuite) Storage() storage.Backend { - return ts.storage -} - -// StorageHumanReadableName retrieves readable identifier of the storage -func (ts *TestSuite) StorageHumanReadableName() string { - return "Rdbms" -} - -// Cleanup tears down test -func (ts *TestSuite) Cleanup() error { - return nil -} diff --git a/pkg/storage/storage_tests/module_storage/storage_benchmark_test.go b/pkg/storage/storage_tests/module_storage/storage_benchmark_test.go index e9ed53d4a..86ae1a8de 100644 --- a/pkg/storage/storage_tests/module_storage/storage_benchmark_test.go +++ b/pkg/storage/storage_tests/module_storage/storage_benchmark_test.go @@ -13,7 +13,6 @@ import ( "github.com/gomods/athens/pkg/storage/mem" "github.com/gomods/athens/pkg/storage/minio" "github.com/gomods/athens/pkg/storage/mongo" - "github.com/gomods/athens/pkg/storage/rdbms" "github.com/stretchr/testify/require" ) @@ -133,10 +132,6 @@ func getStores(b *testing.B) []storage.TestSuite { require.NoError(b, err, "couldn't create mongo store") stores = append(stores, mongoStore) - rdbmsStore, err := rdbms.NewTestSuite(model) - require.NoError(b, err, "couldn't create mongo store") - stores = append(stores, rdbmsStore) - memStore, err := mem.NewTestSuite(model) require.NoError(b, err) stores = append(stores, memStore) diff --git a/scripts/test_unit.sh b/scripts/test_unit.sh index e9c86e723..a7177b3d5 100755 --- a/scripts/test_unit.sh +++ b/scripts/test_unit.sh @@ -2,7 +2,17 @@ # test_unit.sh -source cmd/proxy/.env +if [ -z ${ATHENS_MONGO_STORAGE_URL} ]; then + export ATHENS_MONGO_STORAGE_URL="mongodb://127.0.0.1:27017" +fi + +if [ -z ${GO_ENV} ]; then + export GO_ENV="test" +fi + +if [ -z ${POP_PATH} ]; then + export POP_PATH="${PWD}/cmd/olympus" +fi # Run the unit tests with the race detector and code coverage enabled set -xeuo pipefail