-
Notifications
You must be signed in to change notification settings - Fork 28
DOCSP-44647: add to existing app #55
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
Changes from 4 commits
a25eede
78083c9
8310a07
c3592be
85f7765
772600e
6b38408
b876e64
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,232 @@ | ||||||||||||||||||
| .. _mongoid-add-to-existing: | ||||||||||||||||||
|
|
||||||||||||||||||
| ====================================== | ||||||||||||||||||
| Add {+odm+} to an Existing Application | ||||||||||||||||||
| ====================================== | ||||||||||||||||||
|
|
||||||||||||||||||
| .. facet:: | ||||||||||||||||||
| :name: genre | ||||||||||||||||||
| :values: tutorial | ||||||||||||||||||
|
|
||||||||||||||||||
| .. meta:: | ||||||||||||||||||
| :keywords: ruby framework, odm, migrate | ||||||||||||||||||
|
|
||||||||||||||||||
| .. contents:: On this page | ||||||||||||||||||
| :local: | ||||||||||||||||||
| :backlinks: none | ||||||||||||||||||
| :depth: 2 | ||||||||||||||||||
| :class: singlecol | ||||||||||||||||||
|
|
||||||||||||||||||
| Overview | ||||||||||||||||||
| -------- | ||||||||||||||||||
|
|
||||||||||||||||||
| In this guide, you can learn how to add {+odm+} to an existing Sinatra | ||||||||||||||||||
| or Ruby on Rails (Rails) application. To learn how to set up a new | ||||||||||||||||||
| application that uses {+odm+}, see one of the following guides: | ||||||||||||||||||
|
|
||||||||||||||||||
| - :ref:`mongoid-quick-start-rails` | ||||||||||||||||||
| - :ref:`mongoid-quick-start-sinatra` | ||||||||||||||||||
|
|
||||||||||||||||||
| Sinatra Application | ||||||||||||||||||
| ------------------- | ||||||||||||||||||
|
|
||||||||||||||||||
| To start using {+odm+} in an existing Sinatra application, you can follow | ||||||||||||||||||
| the same steps described in the | ||||||||||||||||||
| :ref:`Sinatra Quick Start <mongoid-quick-start-sinatra>` guide. | ||||||||||||||||||
|
|
||||||||||||||||||
| The following steps describe how to add {+odm+} to a Sinatra application: | ||||||||||||||||||
|
|
||||||||||||||||||
| 1. Add the ``mongoid`` dependency to your application's ``Gemfile``. | ||||||||||||||||||
|
|
||||||||||||||||||
| #. Create a ``config/mongoid.yml`` configuration file and specify your | ||||||||||||||||||
| connection target. | ||||||||||||||||||
|
|
||||||||||||||||||
| #. Create an application file and load your configuration file. | ||||||||||||||||||
|
||||||||||||||||||
|
|
||||||||||||||||||
| #. Create {+odm+} models. | ||||||||||||||||||
|
|
||||||||||||||||||
| Rails Application | ||||||||||||||||||
| ----------------- | ||||||||||||||||||
|
|
||||||||||||||||||
| You can add {+odm+} to an existing Rails application to run alongside | ||||||||||||||||||
| other ActiveRecord adapters. To use a combination of adapters, you | ||||||||||||||||||
|
||||||||||||||||||
| can add the ``mongoid`` dependency and populate the configuration file | ||||||||||||||||||
| with your connection information to start using MongoDB in your | ||||||||||||||||||
| application. | ||||||||||||||||||
|
|
||||||||||||||||||
| To adapt an existing Rails application to use only {+odm+} instead of | ||||||||||||||||||
| ActiveRecord, you must make other configuration changes, as | ||||||||||||||||||
| described in the following sections. | ||||||||||||||||||
|
|
||||||||||||||||||
| Modify Dependencies | ||||||||||||||||||
| ~~~~~~~~~~~~~~~~~~~ | ||||||||||||||||||
|
|
||||||||||||||||||
| Add the ``mongoid`` gem to your application's ``Gemfile``: | ||||||||||||||||||
|
|
||||||||||||||||||
| .. code-block:: ruby | ||||||||||||||||||
| :caption: Gemfile | ||||||||||||||||||
|
|
||||||||||||||||||
| gem 'mongoid' | ||||||||||||||||||
|
|
||||||||||||||||||
| To use {+odm+} as the *only* database adapter, remove or comment out any | ||||||||||||||||||
| RDBMS libraries such as ``sqlite`` or ``pg`` listed in the ``Gemfile``. | ||||||||||||||||||
|
||||||||||||||||||
| RDBMS libraries such as ``sqlite`` or ``pg`` listed in the ``Gemfile``. | |
| RDBMS libraries listed in the ``Gemfile``, such as ``sqlite`` or ``pg``. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Open the ``config/application.rb`` file and examine the contents. If it | |
| requires all the components of Rails by including the ``require | |
| 'rails/all'`` specification, change this to specify individual | |
| frameworks. | |
| Open the ``config/application.rb`` file and examine the contents. If the | |
| file uses the ``require "rails/all"`` statement to load all Rails components, | |
| delete this statement. You must add a separate ``require`` statement | |
| for each Rails component. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: tip admonition
| To verify the contents of ``rails/all`` for Rails 7, see the | |
| :github:`rails GitHub repository | |
| </rails/rails/blob/7-0-stable/railties/lib/rails/all.rb>`. | |
| .. tip:: rails/all Components | |
| To verify the contents of ``rails/all`` for Rails 7, see the | |
| :github:`rails GitHub repository. </rails/rails/blob/7-0-stable/railties/lib/rails/all.rb>` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think we can just delete this note.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| demonstrates how to specify individual frameworks instead of using ``rails/all``: | |
| demonstrates how to load frameworks individually instead of through ``rails/all``: |
side question: is "frameworks" the right word here? a couple of sources i found use "components" or "libraries" instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see frameworks used in some other references + this was in the original guide that I am adapting
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solid idea to show how to do this in code. if this is a comprehensive list, and if it isn't too burdensome to keep current, it might be good to direct them here from the opening paragraph ("...as shown in the following code example:")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure I totally understand what you mean. This list isn't necessarily what a user would need in their application to use Mongoid, it just demonstrates how to load frameworks individually.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `ActiveStorage <https://edgeguides.rubyonrails.org/active_storage_overview.html>`__ and | |
| `ActiveStorage <https://edgeguides.rubyonrails.org/active_storage_overview.html>`__, and |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S:
| Review your application's configuration files, such as | |
| ``config/application.rb``, then remove or comment out any references to | |
| ``config.active_record`` and ``config.active_storage``. | |
| In ``config/application.rb`` and your application's other configuration files, | |
| remove or comment out any references to | |
| ``config.active_record`` and ``config.active_storage``. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Q: do you have to adjust the models in order to migrate? or do you adjust the models such that they can migrate? if it's the former, maybe something like this is clearer:
| If your application already uses models, you must adjust them to | |
| migrate from using ActiveRecord to {+odm+}. | |
| To migrate from ActiveRecord to {+odm+}, you must adjust your application's models, | |
| if it uses any. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| ActiveRecord models derive from ``ApplicationRecord`` and do not have | |
| ActiveRecord models derive from the ``ApplicationRecord`` class and do not have |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: is there a way to tie these four sentences together more? i'm guessing it's explaining how you need to change your models to use Mongoid, but it reads more like a list--in which case, maybe just make it an actual list?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will workshop
Check failure on line 169 in source/add-existing.txt
GitHub Actions / TDBX Vale rules
[vale] reported by reviewdog 🐶
[MongoDB.NegativeWords] Use 'remove, delete' instead of the negative word 'destroy'.
Raw Output:
{"message": "[MongoDB.NegativeWords] Use 'remove, delete' instead of the negative word 'destroy'.", "location": {"path": "source/add-existing.txt", "range": {"start": {"line": 169, "column": 38}}}, "severity": "ERROR"}
Check failure on line 183 in source/add-existing.txt
GitHub Actions / TDBX Vale rules
[vale] reported by reviewdog 🐶
[MongoDB.NegativeWords] Use 'remove, delete' instead of the negative word 'destroy'.
Raw Output:
{"message": "[MongoDB.NegativeWords] Use 'remove, delete' instead of the negative word 'destroy'.", "location": {"path": "source/add-existing.txt", "range": {"start": {"line": 183, "column": 38}}}, "severity": "ERROR"}
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Or, you can define the ``Post`` model by using dynamic fields, as shown | |
| Instead of using [blank], you can define the ``Post`` model by using dynamic fields, as shown |
Check failure on line 196 in source/add-existing.txt
GitHub Actions / TDBX Vale rules
[vale] reported by reviewdog 🐶
[MongoDB.NegativeWords] Use 'remove, delete' instead of the negative word 'destroy'.
Raw Output:
{"message": "[MongoDB.NegativeWords] Use 'remove, delete' instead of the negative word 'destroy'.", "location": {"path": "source/add-existing.txt", "range": {"start": {"line": 196, "column": 38}}}, "severity": "ERROR"}
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: maybe my own ignorance, but this feels tacked on to the previous section instead of a logical continuation, so maybe a note admonition would be useful. maybe even move to the next section (or delete altogether), since it makes this same point.
| {+odm+} does not use ActiveRecord migrations, because MongoDB does not | |
| require a defined schema before you can store data. | |
| .. note:: ActiveRecord Migrations | |
| {+odm+} does not use ActiveRecord migrations, because MongoDB does not | |
| require a defined schema before you can store data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deleted
Check failure on line 206 in source/add-existing.txt
GitHub Actions / TDBX Vale rules
[vale] reported by reviewdog 🐶
[MongoDB.ConciseTerms] 'must' is preferred over 'have to'.
Raw Output:
{"message": "[MongoDB.ConciseTerms] 'must' is preferred over 'have to'.", "location": {"path": "source/add-existing.txt", "range": {"start": {"line": 206, "column": 65}}}, "severity": "ERROR"}
Check failure on line 229 in source/add-existing.txt
GitHub Actions / TDBX Vale rules
[vale] reported by reviewdog 🐶
[MongoDB.Accessibility] Don't use language (such as 'normal') that defines people by their disability.
Raw Output:
{"message": "[MongoDB.Accessibility] Don't use language (such as 'normal') that defines people by their disability.", "location": {"path": "source/add-existing.txt", "range": {"start": {"line": 229, "column": 35}}}, "severity": "ERROR"}
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| .. _mongoid-quick-start-sinatra: | ||
|
|
||
| ===================== | ||
| Quick Start (Sinatra) | ||
| Quick Start - Sinatra | ||
| ===================== | ||
|
|
||
| .. facet:: | ||
|
|
@@ -24,6 +24,9 @@ This guide shows you how to use {+odm+} in a new Sinatra web application, | |
| connect to a MongoDB cluster hosted on MongoDB Atlas, and perform | ||
| read and write operations on the data in your cluster. | ||
|
|
||
| To learn how to migrate an existing application to use {+odm+}, see the | ||
|
||
| :ref:`mongoid-add-to-existing` guide. | ||
|
|
||
| .. tip:: | ||
|
|
||
| If you prefer to connect to MongoDB by using the {+ruby-driver+} without | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
S: