loongmxbt

loongmxbt

How to change a Phoenix Project name smoothly?

I use mix phoenix.new paper to create a new project paper.

So all the stuff is called Paper or :paper.

However, I have to define a model called paper. So I have something like defmodule Paper.Paper do.

When I have multiple aliaes, I need to move Paper.paper to the last.

I know I made a “stupid” codename that may interfere with the model name.

So how can I modify all the Paper. stuff and :paper stuff eaisly? Is there a Phoenix mix command to do that?

Thanks!

Marked As Solved

nerdyworm

nerdyworm

I’ve been using this script for the two or three times I had to rename a phoenix project: rename a phoenix project · GitHub

requires ack to be installed, but you could certainly swap that out for grep.

Cheers,
Ben

12
Post #5

Also Liked

jaysoifer

jaysoifer

• Works on MacOS, not tested elsewhere.
• Needs: git, xargs and sed.

From the root folder of the project:

  1. git grep -l 'old_name' | xargs sed -i '' -e 's/old_name/new_name/g'

  2. git grep -l 'OldName' | xargs sed -i '' -e 's/OldName/NewName/g'

  3. mv ./lib/old_name ./lib/new_name

  4. mv ./lib/old_name.ex ./lib/new_name.ex

    If you have a similar folder structure in the tests folder, you probably also need:

  5. mv ./test/old_name ./test/new_name

11
Post #6
benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

There is not a command for renaming a project. I have however had to do so a couple times in the past, and in general global find and replace works really rather well. Just also move any directories named paper and you’re done.

Qqwy

Qqwy

TypeCheck Core Team

A global find+replace works a lot better in Elixir than in most OOP-languages, because you always refer to a certain piece of code the same way: ModuleName.function_name. And structs use the ModuleName as well.

In OOP-languages, you can only hope that some object isn’t referred to under a different name.

Where Next?

Popular in Questions Top

Kurisu
For example for a current url like http://localhost:4000/cosmetic/products?_utf8=✓&query=perfume&page=2, I would like to get: ...
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
qwerescape
Is there a way to get the call stack or stack trace at any point in the code? Not from exceptions, but an expression that returns how the...
New
mgjohns61585
Could someone help me? I’m making my first elixir program, number guessing game. I can’t figure out how to convert the user’s guess from ...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
New

Other popular topics Top

Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 29703 241
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
Fl4m3Ph03n1x
About me? ( if you have nothing better to do than reading about some random guy in the internet :stuck_out_tongue: ) Hello all, this is ...
New
stefanchrobot
What’s the safe way to decode a JSON string into a struct? I want to avoid calling String.to_atom. Jason.decode can give me a map with st...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
svb
Hi! Currently I want to submit a form by pressing the Enter key. However, since my input field is of type “textarea” this is just adds a...
New

We're in Beta

About us Mission Statement