Can you create a ruby api application on top of existing schema? - ruby

I am fairly new to Ruby on Rails. I am using it to create a web API application and was wondering if instead of creating a schema based on my Model, can I do the reverse? E.g. is it possible to create model that would fit with an already existing schema? Something like that would be fairly easy in Java World using JPA but I am not so sure about Rails using DSL for databases.
Do I have to manually change the migration files in this case? If yes, is there an easy/recommended way to do this?
Thanks

The only thing that you have to do is to add ActiveRecords with the name of your tables.
https://guides.rubyonrails.org/active_record_basics.html
And yes there is way to reverse engineer it.
There is pretty good article about that: https://codeburst.io/how-to-build-a-rails-app-on-top-of-an-existing-database-baa3fe6384a0

Related

Can we have multiple database instances on a Ruby project using Hanami?

Currently we have a single Aurora Postgresql db instance that we are interacting with but I would like to add one more db instance so that we can read from one database and write to another(existing one). We are using Hanami v1.3 and the project is in ruby.
I am trying to find documentation/resources on how to implement this and is it possible to do so?
This is not possible in Hanami v1.3, checkout the following link:
https://github.com/hanami/hanami/issues/1028
In hanami 2 (already in beta 🥳) it is possible through rom-rb (you will love to work with it). I would not recommend to start a new project with hanami 1.3. I would go definitely with 2.0.

Strapi - how to migrate content

I'm looking to use Strapi for a client of mine and I was wondering if there were best practices to migrate content from one environment, for example staging to production? My client has a lot of content, so recreating all the content on each environment is not viable.
Thanks a lot !
For now, the only raw solution is to dump your database ...
I think that the best option is to create a module that let you import/export content.
But keep in mind that migrate content between environment is never the best option. Your client probably want to see only the final state, but you probably want test content that use every spec' of your app.

Is there a tool to manage elasticsearch migration

I just started with ElasticSearch and I wish to automate migration between code versions.
For RDBMS I use tools like phinx that apply changes to the DB.
For example:
Create a migration file with up() & down() methods.
Write commands to apply (for example add index).
after tests and etc ./phinx migrate.
Is there a migration tool like this?
If not, is there another acceptable approach to handle changes to the cluster?
I have never heard of a tool like that specifically for ES indexes.
If your goal is to update the internal representation of your data, i think the best approach is just create a script that:
Find the affected documents
Read the contents
Modify them
Reindex them in a new doc
Then you can delete the old document.
Update a doc it wont be more efficient that reindex, since documents are immutable, so update is just get + reindex (https://www.elastic.co/guide/en/elasticsearch/guide/current/update-doc.html)
Flyway with code-based (e.g. Java) migrations can be used to work with any data store. Similar to migrating relational DB, but requires a bit more work since you need to implement calls to ElasticSearch with the relevant commands (e.g. create index).
https://flywaydb.org/documentation/concepts/migrations.html#java-based-migrations
Coming from a background of RDBMS, the migration tool is very handy when you are working with a big project that is having a lot of migrations files. I was also facing the same issue with Elasticsearch that currently there was no stable migration tool in the community.
I have created a migration tool and it will be handy if you are coming from a background of python https://pypi.org/project/chalan/. The core idea is taken from Alembic migration tool that is for Sqlalchemy.
Usage is simple
pip install chalan
Then for upgrade you have to use
chalan upgrade
And for downgrade you have to use
chalan downgrade
Please let me know if you face any issues with this tool and feel free to suggest some improvements if any.
For source code please refer the github link - https://github.com/anandtripathi5/chalan

Is it possbile to change the webpages_Membership, roles etc table names from a simple template created with web matrix?

I've created a Web Matrix web site from the starter template which creates a database with the a few tables for the login details. Most of these are names webpages_Membership, webpages_Roles etc. The hosting company I use only gives me one database and I want to have more than one site on the server. I want to prefix the table name with something to make it unique, but it looks like the web matrix framework will only work with the set table name. Does anyone know if this is possible?
If you use SQL Server Compact Edition, you can have as many databases as you like in your App_Data folder. Certainly something to consider if your sites aren't likely to be hugely busy. Otherwise you can develop your own Provider inheriting from ExtendedMembershipProvider and make it "site-aware". Dig around in the WebMatrix.Data source code for more details (available as part of the MVC source download).

Create new user in sonar

Is it possible to create a new user in sonar without using the web interface?
I need to write a script that inserts the same users for some tools, including sonar.
There are three ways you can do this:
Write directly to the database (there is a simple table called users).
Use the LDAP plugin, if you specify sonar.authenticator.createUsers: true in sonar.properties, it will create the users in the sonar database automatically the first time they authenticate.
Write a java application that depends on the sonar plugin API, you can then use constructor injection to get a Sonar hibernate session and persist the user you want. See Here.
Since SonarQube version 3.6, there is support for user management in webservice API:
https://sonarqube.com/web_api/api/users
http://docs.sonarqube.org/display/DEV/Web+API
The web service API does not seem to support user management. Anything's possible, but it doesn't look like this is offered directly via Sonar.
You could probably use some web automation library (webbrowser, webunit, watir, twill) to do it through the running server; it might even be possible to just use something like 'curl' by looking carefully at the page source for the users/create form.
Or, if you want to go straight to the database, you could try to pull out the user creation functionality from the code and mess with the sonar.users table directly.
There is the LDAP Plugin, which would take care of authentication, but it still requires you to create the users in Sonar, so that wouldn't solve your problem.

Resources