Giter Club home page Giter Club logo

localtower's Introduction

Gem Gem

Localtower

Introduction

- What is Localtower?

Localtower is a Rails Engine mountable in development environment to help you generate migrations for your Rails application. It's like ActiveAdmin or Sidekiq UI. You plug it in your config/routes.rb and it works out of the box. Check the Installation section below for more details.

- How Localtower works?

Localtower gives you a UI to create models and migrations. It will generate a migration file like you would do with rails generate migration add_index_to_users. You will see the generated file in db/migrate/ folder.

- Why creating a UI for Rails migrations?

Rails migrations are well documented in the official Rails Guides but we often tend to forget some commands or do typo errors. Like writing add_index :user, :email instead of add_index :users, :email (did you spot the typo?). Working from a UI with a fixed list of commands reduces the chance of making errors.

- When I'm using Localtower, can I still generate migrations from the command line?

Of course! Localtower does not lock you up. You can still generate migrations like you did before. Localtower is just a migration generator. You can also generate a migration from Localtower and then edit it manually before running rails db:migrate

- What does happen when I want to remove Localtower?

You just have to remove the gem from your Gemfile, run bundle, remove the engine in config/routes.rb, and that's it! All your previous migrations will stay in db/migrate/. You are never locked up with Localtower. You can install or uninstall anytime. Remember, it is just a UI to generate files. Do not hesitate to open an issue on Github and tell me why you don't want it anymore. It will be very valuable for me to understand what I can do better ❤.

- Cool, but there are some migration options that are not available in Localtower, what can I do?

Localtower doesn't implement all the Rails Migrations API. I focused on the most common scenarios. If you need to do something tricky in your migrations, you can still edit the migrations manually. You are also welcome to open an issue on Github to ask for a specific feature. I'm always open to extend the possibilities of Localtower.

Screenshots

Create a model

New Model

Create a migration

New Migration

See the Models

Models

See the Migrations (and migrate)

Migrations

Installation

Please use localtower version >= 1.0.0 See installation process below.

Compatibility:

  • Rails >= 5.2
  • Ruby >= 2.3

Add to your Gemfile file:

# In your current group 'development':
group :development do
  # [probably other gems here]
  gem 'localtower'
end

# Or as a one liner:
gem 'localtower', group: :development

Run command in your terminal:

bundle install

Add to your config/routes.rb:

MyApp::Application.routes.draw do
  if Rails.env.development?
    mount Localtower::Engine, at: 'localtower'
  end

  # Your other routes here:
  # ...
end

⚠ IMPORTANT ⚠

Change your config/environments/development.rb:

Rails.application.configure do
  # This is the default:
  # config.active_record.migration_error = :page_load

  # Change it to:
  config.active_record.migration_error = false if defined?(Localtower)

  # ...
end

If you know how to override this configuration in the gem instead of doing it in your app code, please open an issue and tell me your solution.

Usage

To access the UI, run your local rails server and open your browser at http://localhost:3000/localtower.

Upgrading

I recommend you to upgrade to the latest version which is 1.0.0. To upgrade, just use the latest version of Localtower:

bundle update localtower

Roadmap

  • Be able to use uuid instead of id as primary when creating models.
  • Realtime preview of the migration files
  • Better frontend validation

Contribute

Thanks for reporting issues, I'll do my best to fix the bugs 💪

ga

Run test

If you want to contribute to the gem:

Create a spec/dummy/.env file with the credentials to your PostgreSQL Database. It should look like this:

LOCALTOWER_PG_USERNAME="admin"
LOCALTOWER_PG_PASSWORD="root_or_smething"

Run the spec:

bundle install
bundle exec rspec spec/

Deploy latest gem version

Only for official contributors.

git tag v1.0.0 # change by last version
git push --tags
rm *.gem
gem build localtower.gemspec
gem push localtower-*.gem

Notes

Do not hesitate to open issues if you have troubles using the gem.

localtower's People

Contributors

bthachdev avatar damln avatar dmytrovasin avatar lex111 avatar rasmachineman avatar sergio-rivas avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

localtower's Issues

Not able to generate model

screen shot 2017-09-01 at 11 03 21 am

Parameters are

{"utf8"=>"✓",
 "authenticity_token"=>"bxCtjP64fG5B2hdWJVgpo4sBPuZDfVhshbDqqb3mJpKwfBk9M0Up4GJblundWqlUkD04tro4xTq/kpLzyIVHcg==",
 "models"=>{"model_name"=>"something", "attributes"=>[{"attribute_name"=>"something", "attribute_type"=>"string", "defaults"=>"", "index"=>"true", "nullable"=>"true"}], "run_migrate"=>"false"}}

Version:
Rails: 5.1.3
Postgres: 9.6

Note: I am using localtower with rails api

Option to opt a relation between models

Thanks for the great gem!!! In right time this gem rescued me from schema and migration problems. While I am using this gem, I found that we can't opt a relation between two models. Could we add this feature ?

Again thanks for the great effort!!!!

array migration fail

when adding a "New Model", and choosing "array" as one of the types for a new column, the migration fails.

When using localtower to add a "New Migration" the choice for array works perfectly. I noticed that New Migration adds two lines:
add_column :target_model, :column_name, :text, default: [], array: true add_index :target_model, :column_name, using: :gin

However, adding a "New Model" and choosing array, only adds this one line inside the "create_table" action:
t.array :column_name

=============

SOLVED: I was using an old version of localtower.

Suggested Feature: Add_References

For migrations, it would be great if you could add a “add_references” type of migration that generates migration similar to the terminal command "rails g migration AddAccountToUsers account:references"

Currently the only way to add references for a belongs_to relationship is "add_column"
screen shot 2017-03-09 at 9 47 52 pm

Problem:
The problem with this is that novice users might make mistakes in the naming of the column. Example: naming it "account" vs "account_id", which can lead to the reference being applied inappropriately.

Solution:
A simple solution would be to add a "add_references" action for the migration creations. Then in the "COLUMN" section of the form, have the user pick the "target table" for which the model belongs to (Example:
Action: Add_references,
Model: User,
Column: Account)

Then when submitting it, have the following type of migration generate:
screen shot 2017-03-09 at 9 48 15 pm

Crash After Deleted Table

I encountered a bug in localtower.

Steps to crash:

  1. I created two separate models before using local tower (users and accounts).
  2. I used Localtower to create relationship (which added a table “account_users”)
  3. I realized that this isn’t what I wanted to do, so I tried dropping the tower in localtower.
  4. The drop didn’t work so well it seems… So I tried to do a db:rollback
  5. After I did db:rollback and deleted the migration that created the table account_users, my rails app works perfectly. However, if I go to localhost:3000/localtower/ I get an error message.

Error Message:

screen shot 2017-03-09 at 9 31 50 pm

Not sure of the cause, but I have a few ideas. One idea is that it might be related to loading the schema from a cache?

screen_shot_2017-03-09_at_9_37_35_pm

EDIT:: After messing around and doing some debugging around my app, I found the problem.

The Problem:
I still had a "models/account_user.rb" file after dropping the account_user table
After I deleted that file, it started to work perfectly again.

Suggestions:

I think you should change the way the schema-load algorithm works. Currently, localtower seems to depend itself on the user following convention in his models. This could be a huge problem for new users who haven't learned these conventions. What if, for example, a user creates a helper ruby file and saves it in the models folder?

Possible Solutions:

  • Make the schema load be dependent on searching through the text of "db/schema.rb", then afterwards, search for appropriate models, etc.
  • Load models and schema separately to be able to show a warning message to user indicating that there are models that exist without a corresponding db table.
  • After dropping a table, perhaps local tower can automatically move the file out of "models" folder and into a different folder (ex: "DeprecatedModels" folder) [this way if a user accidentally drops the table, he won't lose any code/methods written into the model.]

Rails 5.1

Hi,

Is the lock < 5.1 since 0.2.3 intentional, do you have a Rails 5.1 related issue?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.