Symfony 1.4, sfGuardPlugin with existing user table/model - symfony1

I have symfony 1.4 installed and had setup my own user model (table). Now, in order to use sfFacebookConnectPlugin, it asks to use sfGuard plugin, so it can easily integrate existing users with facebook account.
Is there a way to use sfGuardPlugin with existing user model ?
OR
is there a better way to implement facebook connect, such that it recognizes the same user (by email), if exists, or creates a new user in the user table with the fb email id and also creates the session.
Thx !

You can use sfGuardPlugin with an existing model, the schema file will be loaded from the plugin's folder and the table names are namespaced in a way that prevents naming collisions.
All you have to do is install the plugin as per its installation instructions and then build your model. To deploy to production you can either copy the SQL that propel generates (in data/sql) and execute it or use a program like Toad for MySQL to generate diff sql upgrade scripts.
Have you tried and failed? I hope I've addressed your concerns.

Related

Converting a single Tenant Application to a multitenant one using Apartment gem

I've built a single tenant rails application with all core features ready to ship. But I now want to make it multi-tenant using the apartment gem. Most tutorials I've found all show how to start from scratch. But I find no pointers on how to convert an existing project to have multi-tenancy built in. From my research I found that all models need a tenant ID added in the migration. How do I add this to all existing models easily? Does installing the gem and running the generator suffice? I'm running a rails 5 API application with close to 30 models and using graphql ruby in an Ubuntu 18.04 environment.
Any ideas on how to do this?
Thanks #lacostenycoder for pointing me in the right direction. Here's what I did.
Short answer: Yes, installing the gem, running the generator and creating your tenant model should suffice. Apartment reads your schema and creates schemas for the tenants.
Long answer, my experience:
I Backed up existing data from my database just in-case.
Installed apartment gem
If you are using any PostgreSQL database extensions like I was (pgcrypto, uuid- ssop)you need to understand that the extensions are not automatically loaded into the newly created schema.(look here for more details) do the following:
Follow instructions the github readme to create a shared_extensions schema
Create your first tenant. If it works, all is well. But...
If that doesn’t work, I mean when you create a tenant you get errors like ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: function gen_random_uuid() does not exist
or ActiveRecord::StatementInvalid: PG::UndefinedFunction: ERROR: function uuid_generate_v4() does not exist (more details here, here and here) like it was my case when creating my first tenant, I discovered that once the extensions are enabled on the public schema, they cannot be installed in the shared schema shared_extensions in this case. So you have to change them from the public schema to the shared_extensions schema. get more details here
If you are using uuid-ossp ALTER EXTENSION "uuid-ossp" SET SCHEMA shared_extensions in your rails dbconsole
If you are using pgcrypto ALTER EXTENSION "pgcrypto" SET SCHEMA shared_extensions in your rails dbconsole
The apartment gem will create all models for your tenant once you have it set up correctly and create your first tenant.
For more information on check out some of these github issues on apartment. Here and here.
Took me a day to figure it out and gather that info. I hope it saves you time and headache!
There doesn't appear to be any reason why you can't add this to an existing Rails app. I have not done this myself, nor does there appear to be any specific tutorials on how to migrate an existing app. Follow the gem setup instructions as shown on the README and also see the wiki for additional configurations and instructions. Use TDD wherever possible and expect to make changes to your application to get everything working correctly. Depending on how complex your existing app is will determine how much work this move will be.
You'll likely want to use lvh.me:3000 instead of localhost:3000 as root domain and port in your browser and perhaps use rails s -b lvh.me when starting your local server.
If you want to safely hack through this branch I recommend that you make a full backup of your local development database before you get started so that you can rollback to your stable current version in the event things go horribly wrong. If you're using Postgres for example there's pg_dump and pg_restore
This approach combined with good TDD should get you where you need to be.

Devise: how to migrate users from one project to another

Wondering if anyone tried this before, I'm trying to migrate devise users from one project(postgres) to another(mongoid).
I've created a script with takes users from sql table and create mongo inserts out of it, all was running fine, but for some reason devise on new project not able to auth migrated users.
encrytpted_password field looks ok.
Can someone please advise if I've missed something?

automatically generate API for existing database

Is there any way to automatically generate Rails API for existing database? I have mysql DB from php project and I need to generate REST API for it.
using rails 4, you could use scaffold, taking care to keep the data models exactly like the old database (ie. same table and column names), then remove the migrations that are generated with the scaffold.
let's say you have a table called Posts, with columns: subject and body.
You could run:
rails g scaffold post subject:string body:text
Then remove the migration from db/migrate.
Now assuming you set up the rails app to access the database correctly via config/database.yml, you should have a json API all set up and ready to use, since rails scaffold generates index.json.jbuilder and show.json.jbuilder for each resource that you scaffold.
You might have to edit the application controller to allow external API requests, but this should only matter if you plan on POSTing to your API:
if you do need to POST, then change this line in the top of your app/controllers/application_controller.rb:
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
to this:
protect_from_forgery with: :null_session
GET requests should work without modifying the application controller.
Forgot to mention, to access these resources, you will use ?format=json as a parameter, so:
http://localhost:3000/posts?format=json
or
http://localhost:3000/posts/1?format=json
Will return the json response for all posts or a single post.
you can use AutomaticApiRest [automaticapirest.info], This project was created by myself last year. Basically, this tool allows to create an API REST of your DB (MySQL) in seconds.
Features
Creation a powerful API REST of your MySQL Data Base in Seconds.
Management of the API in situ, it is not neccesary an extra data base.
Private tables and fields.
Custom queries.
Installation
Download the source or clone the repo.
git clone https://github.com/GeekyTheory/Automatic-API-REST
Place it in /var/www/YourWebPage/ (for Apache).
Open the file config.php and complete all the fields with the server credencials.
Go to domain.com/AutomaticaApiRest
There is a Node.js alternative in which you can use any SQL database(MySQL, MSSQL, SQL Server, Aurora, PostgreSQL, and SQLite). I'm one of the core committers of that project.
Install the CLI tool(xc-cli) globally from npm using the following command:
npm install -g xc-cli
Then you can create the project simply using following command:
xc new <project_name>
Note : It would prompt for database connection details, just enter the connection details and it would do the rest of the code generation. And you have to install GUI tool to work the code generation(Download it from here: https://github.com/xgenecloud/xc-desktop-app/releases)
For more info refer GitHub repo: https://github.com/xgenecloud/xgenecloud
And for documentation refer: http://docs.xgenecloud.com/

Migration For a Modular System

I want to create a modular system.I have a problem about concept of migration in my project.
I need a series principle about create Modules and do migration. For example assume I am creating a PersonService Module and create database according to Models Of this module, then in next Version of this module I must change a model of it.I will sale new module to customer and then the customer's database must be updated according to new model. This process must do automatically. But my questions Are:
How can I migrate my database Automatically in customer system?
What principle is important to create module and database?
can customer update database,If customers want to install old version of module ?
------------------------EDIT-------------------------------
what model is better to use?Code-First?Database-First?Or....?
Do I corrupt customer's data with Automatic migration?
thank again
You can deploy the most recent version of your application using Automatic Database Migrations to the customer and upon the next run it will update provided you have Automatic Migrations enabled in your configuration.cs file in the Migrations folder. If you have any logic depending on these fields or tables though you need to be sure to populate data during the migration or disable that logic until after data has been populated some how.
To add on to this if you want them to always begin with a baseline database during the initial install you need to enable migrations at that point before you add existing fields or tables to your model, and therefore your database. If you update the model and want to back date the install to a previous model version you are out-of-luck unless you build extensive code to revert to a previous migration that you never created.

Why rails doesn't want you to create rails projects within existing rails project

I want to create another project inside exisiting rails app. My reasoning is that:
They have some common models which I would be able to link to from the inner app,
They operate on the same database
They will have one version control system (no additional configuration and moving required)
Apart from why I want to do that I just want to know why rails prevents you from doing that? As of my testing, no conflicts were exposed.
You should be using Rails Engines for this. Here's a Railscasts episode about it. http://railscasts.com/episodes/149-rails-engines

Resources