Remove Ecto from existing Phoenix project
Asked Answered
C

3

7

I have an existing project built with default settings. Now I see that I dont really need Ecto for anything. I just want to remove all DB related events from the code.

Can someone guide me through the process ?

I have removed all mention of Ecto from mix.exs but I guess thats not enough

Update:

I found ecto mentioned in lib/api_test/repo.ex file. If I remove the line it gives the following error

=INFO REPORT==== 21-Jul-2016::12:43:30 ===
    application: logger
    exited: stopped
    type: temporary
** (Mix) Could not start application api_test: ApiTest.start(:normal, []) returned an error: shutdown: failed to start child: ApiTest.Repo
    ** (EXIT) an exception was raised:
        ** (UndefinedFunctionError) function ApiTest.Repo.start_link/0 is undefined or private
            (api_loc) ApiTest.Repo.start_link()
            (stdlib) supervisor.erl:365: :supervisor.do_start_child/2
            (stdlib) supervisor.erl:348: :supervisor.start_children/3
            (stdlib) supervisor.erl:314: :supervisor.init_children/2
            (stdlib) gen_server.erl:328: :gen_server.init_it/6
            (stdlib) proc_lib.erl:247: :proc_lib.init_p_do_apply/3
Cydnus answered 21/7, 2016 at 7:1 Comment(3)
I will start removing phoenix_ecto from the deps and look where the compiler start complaining. The compiler where not complaining after deleting ecto from mix.exs ?Bookbinding
You could create a new phoenix project with the --no-ecto flag and then compare it to your existing one.Morphia
Do you still have a line such as worker(ApiTest.Repo, args), mentioned somewhere? See if Repo is still mentioned somewhere in your project.Moue
M
16

I think I have a good solution for you. I created two fresh Phoenix projects, one with Ecto, one with the --no-ecto flag (mix phoenix.new --no-ecto my_app). I then initialised a Git repo in the one with Ecto, added and commited everything and then deleted all files and replaced them with the ones from the project without Ecto.

The result is this commit on GitHub. I think there you find a very good starting point on what to change.

Morphia answered 21/7, 2016 at 8:44 Comment(2)
Did you mean you ...replaced them with the one without Ecto?Everything
this helped me a lot. Just follow the commit and delete everything that is marked in red and works like magicJankey
B
4

This can now be done with mix ecto.drop -r MyApp.Repo (where MyApp is the name of the application). See the guides for ecto.drop.

Additionally this could be done manually by deleting MyApp.Repo and the reference in lib/my_app/application.ex under the start function.

Blakely answered 2/1, 2019 at 16:35 Comment(0)
C
0

Got it done.

Basically followed the documentation of Phoenix for including Ecto mentioned at https://hexdocs.pm/phoenix/1.3.0-rc.2/ecto_models.html

Just did the reverse of whatever was mentioned in the document.

Cydnus answered 22/7, 2016 at 11:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.