Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Postgresql in circle #4397

Merged
merged 3 commits into from
Jul 16, 2020
Merged

Postgresql in circle #4397

merged 3 commits into from
Jul 16, 2020

Conversation

jeremyf
Copy link
Contributor

@jeremyf jeremyf commented Jun 30, 2020

Adds optional Postgres setup for test database

cd4c970

Our CircleCI orb gives us the ENV variables this setup uses.

Adding postgresql to the engine cart build

ce1cd77

Thanks @rotated8 for the previous leg of the journey.

For both local development and CircleCI, this commit switches the default
database from Sqlite to Postgresql.

Intrepid developer, please note when next you regenerate the
.internal_test_app, you will by default be generating it to use a
Postgresql database. For now, I've included guidance on what to do in
the ./.engine_cart.yml file.

Once you've regenerated your .internal_test_app, you'll need to export
a DATABASE_URL (or update .internal_test_app/config/database.yml) to
specify how you're connecting to Postgresql.

This builds on the guidance in the Rails Guides around using a
DATABASE_URL environment variable.

Also, ensuring hyrax installs migrations in CirclCI

At a future point, we'll likely need to update the developer Wiki, but
for now, dear developer, you'll need to review the commit messages.

Changing column type [Needs Upgrade Notes]

f33c213

I do not believe this change column is likely used by adopters; It has
to do with adding permissions to an individual Sipity::Entity.

The change is necessary because the foreign key was created as a string,
but the associated primary key on the other table was an integer.

This is likely a bad copy paste job from ndlib/sipity

@@ -5,6 +5,67 @@ class TestAppGenerator < Rails::Generators::Base
# so the following path gets us to /path/to/hyrax/spec/test_app_templates/
source_root File.expand_path('../../../../spec/test_app_templates/', __FILE__)

def conditional_postgresql_for_ci_environment
# For now, postgresql is something we are looking at adding to CircleCI
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could all of this be handled by DATABASE_URL instead? https://edgeguides.rubyonrails.org/configuring.html#configuring-a-database

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we could. I also believe we could then run postgresql OR sqlite locally for specs based on an ENV. That would be dreamy.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some further digging, and those ENV's currently come from CircleCI. Also, based on my read of that configuring a database, you'd be able to use DATABASE_URL for local development.

Perhaps this is something to bump to @rotated8 and samvera's orbs?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jeremyf i think you can set environment variables for a job here, without requiring changes to the orb: https://github.com/samvera/hyrax/blob/master/.circleci/config.yml#L20-L22

i think adding a line like DATABASE_URL: 'postgresql://hyrax_user:hyrax_password@postgres/hyrax?pool=5' might do the trick?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@no-reply I'll give it a go on my local machine; I'd love to remove some of that conditional logic.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly it's okay to just hard code the CI config in multiple ENV variables as a first step, then refactor the duplication out after?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm hearing that it'd be nice if the orb exported a DATABASE_URL variable. So, samvera/samvera-circleci-orb#42

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rotated8 thanks, I'll get to hard-coding, and see about remediating that particular file. I'm a big fan of how small this PR is becoming.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last set of commits and rebasing addresses the DATABASE_URL, and opts for the hard-coding as talked about in https://wiki.lyrasis.org/display/samvera/Samvera+Tech+Call+2020-07-15

It's much cleaner and removes several switches (though pushes people to locally use postgresql when they regen their internal test app).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh wow this looks great! thanks for your documentation.

i appreciate the personal nature of your code comments. :)

@jeremyf jeremyf force-pushed the postgresql-in-circle branch 6 times, most recently from 9d48fb9 to add3dd4 Compare July 1, 2020 20:16
@jeremyf
Copy link
Contributor Author

jeremyf commented Jul 1, 2020

So, even if these specs pass, there appears to be some "fails more than it passes" builds.

I'm going to look into the DATABASE_URL, as I think that might help someone run both a sqlite and a postgresql instance in their dummy app (based on ENV).

I also believe, at this point, that all Postgresql specific changes to the code-base have been merged via other PRs.

@jeremyf jeremyf force-pushed the postgresql-in-circle branch 2 times, most recently from accc6a3 to 2c20f94 Compare July 8, 2020 18:18
@jeremyf jeremyf force-pushed the postgresql-in-circle branch 2 times, most recently from 5e50e76 to 283b453 Compare July 9, 2020 17:34
@jeremyf
Copy link
Contributor Author

jeremyf commented Jul 9, 2020

I rebased the work based on #4417

Our CircleCI orb gives us the ENV variables this setup uses.
@jeremyf jeremyf changed the title Postgresql in circle WIP - Postgresql in circle Jul 15, 2020
@jeremyf jeremyf marked this pull request as draft July 15, 2020 17:26
@jeremyf jeremyf changed the title WIP - Postgresql in circle Postgresql in circle Jul 15, 2020
@jeremyf jeremyf marked this pull request as ready for review July 15, 2020 19:00
Copy link
Member

@cjcolvar cjcolvar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good and pretty clean now!
I have only one small suggestion and a question.

.circleci/config.yml Outdated Show resolved Hide resolved
- run:
command: |
cd .internal_test_app
bundle install
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need another bundle install here? It runs at the engine level right before this.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know; I'll remove and find out. Brace yourselves, rebases are coming!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to remove this, but without the step, things fail.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for trying that out. Not in scope of this PR, but I wonder if this is another place that circleci caching could be utilized.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'd love to not run bundle install more than is necessary. This looks like it shouldn't be necessary, but I leave it up to the next person.

@@ -0,0 +1,40 @@
# Greetings Hyrax developer, you may be surprised to see this file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great!

these docs are helpful. i may take a pass at a docker version later on.

no-reply
no-reply previously approved these changes Jul 15, 2020
Copy link
Contributor

@no-reply no-reply left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 🎸 ✨ 🥇

@@ -112,6 +114,9 @@ jobs:
ruby_version: << parameters.ruby_version >>
bundler_version: << parameters.bundler_version >>
project: hyrax
- run:
command: |
cd .internal_test_app
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like you lost the migration installation and db:migrate in the rebase.

@jeremyf
Copy link
Contributor Author

jeremyf commented Jul 15, 2020

The errors that I'm seeing indicate that I may be missing some necessary build step.

@jeremyf jeremyf force-pushed the postgresql-in-circle branch 2 times, most recently from 8edfdbd to 29b81cf Compare July 15, 2020 23:44
Thanks @rotated8 for the previous leg of the journey.

For both local development and CircleCI, this commit switches the default
database from Sqlite to Postgresql.

Intrepid developer, please note when next you regenerate the
`.internal_test_app`, you will by default be generating it to use a
Postgresql database.  For now, I've included guidance on what to do in
the `./.engine_cart.yml` file.

Once you've regenerated your `.internal_test_app`, you'll need to export
a DATABASE_URL (or update `.internal_test_app/config/database.yml`) to
specify how you're connecting to Postgresql.

This builds on the guidance in the [Rails Guides][1] around using a
DATABASE_URL environment variable.

[1]:https://edgeguides.rubyonrails.org/configuring.html#configuring-a-database
Also, ensuring hyrax installs migrations in CirclCI

At a future point, we'll likely need to update the developer Wiki, but
for now, dear developer, you'll need to review the commit messages.
I do not believe this change column is likely used by adopters; It has
to do with adding permissions to an individual Sipity::Entity.

The change is necessary because the foreign key was created as a string,
but the associated primary key on the other table was an integer.

This is likely a bad copy paste job from ndlib/sipity
Copy link
Member

@cjcolvar cjcolvar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@jeremyf jeremyf merged commit fdd7877 into master Jul 16, 2020
@jeremyf jeremyf deleted the postgresql-in-circle branch July 16, 2020 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants