I am working on multi-tenant system for one Codeigniter setup,for each tenant set new database.
Now my confusion is how to run cron job for all tenant database.
Related
I have multiple databases in my project based on company we are giving new database for that company.i am developing automation workflows in my current project for that i was planned to implemented queue-jobs concept to achieve this one.
we are maintaining one more database which will contain all databases list (companies which are using them).i was little confused how to approach these kind of scenarios,either i have to maintain jobs table in my commonDatabase or if i have to create jobs table inside each database separately.
Note:- EVery time user tried to login he has to give company name(All requests we are sending in headers) that indicates database name.
My doubts are:-
i created jobs table in each database but it's not inserting records
in particular database,instead of it's inserting in commonDatabase
jobs table?
what is the best way to acheive this kind of scenario ?
if any user logged out the queue will run background or not ?
The thing I understand from you question is that you want to covert your project to multi-tenant multi-database and every company will generate a request to build tenant for them. The answers of your question are following:
I created jobs table in each database but it's not inserting records in particular database,instead of it's inserting in commonDatabase jobs table?
I must said you to watch this youtube play list.
If the Job is related to a company process i.e. you want to process any company invoice email then you will dispatch job in company database and if job is related to commonDatabase i.e. you want to configure any company database then run migrations & seeder into it, then it should be dispatch in commonDatabase.
if any user logged out the queue will run background or not?
yes, the queue will still run in background because the queue worker run on server and it doesn't have any concern with login session or any other authentication medium. You must need to read following articles/threads
Official Laravel Doc on queue
How to setup laravel queue worker
i'm using laravel and working on migrations.
I am looking for records of the implementation of migrations. How does Laravel find out how far the migrations have run? Because I have checked that each migraine only runs once and will not run in subsequent commands.
My software has one source and several databases (per user). I would like to know what effect will this have on other users if one of my users executes migraine?
Migrations, once processed are held in the database in a migrations table. If your users have separate databases then they will have their own migrations table. Can't imagine a scenario though where users of the application would be running migrate?
Is there a way to run EF Core migrations on multiple databases having the same set of tables. This is for multi-tenancy architecture where there's a master database (has metadata of all tenant databases including the tenant database connection string) and one database per tenant having the same set of database objects. We need to be able to run these migrations when a new tenant database is created automatically in SaaS model and also run these migrations whenever there are changes to the database structure (new columns, data type changes, new indexes etc.)
I've posted this exact same question on EF Core's GitHub.
The answer is, it can't be done at design time. You basically need to run your migration scripts manually on each tenant's database.
Executing migrations at runtime, however, is easy. You can instantiate a dbContext for each of your connection strings when your app launches (before WebHost.Run() if it's a web app) and execute your migrations like this: dbContext.Database.Migrate();
This is not ideal, of course, because it makes it harder for you to rollback your migrations to a certain point using Visual Studio Package Manager Console or CLI using dotnet ef commands.
The CLI command can be provided a connection string. So you could run it once per db, providing the connection string for each.
The command would look like this:
dotnet ef database update --connection "Server=client1.db;Database=client1"
Our team has about 10 developers, our application is one front-end connect to 20 databases(same scheme), and new database will be add when there is new client. Time to time someone will need update DB scheme, we end up doing this.
if you need scheme change, create SQL script and create the change request by email
only one person in the team run those script, and update database access layer
git push
tell the team dinner is ready
The person doing this created a EXE project for DB migration, he keep adding script to a folder, so the folder will contain all the script
0001.InitTables.sql
0002.MoreTabels.sql
0003.UpdateDropdowns.sql
.
.
.
then he use a library like DbUp (https://dbup.readthedocs.io/en/latest/) help him track those scripts and run on DB server.
He will run for DEV server first, on the release date, he will run this for production.
List<string> connectionStrings=new List<string>{
"ConStr1","ConStr2", "ConStr3"
};
foreach(var conStr in connectionStrings){
var upgrader = DeployChanges.To
.SqlDatabase(conStr)
.WithScriptsEmbeddedInAssembly(
Assembly.GetExecutingAssembly()
)
.LogToConsole()
.Build();
var result = upgrader.PerformUpgrade();
}
I'm building a multi-tenant saas application using laravel 5.7 and vuejs. Whatever new client register the system will create new database for him as well all table migrations and seeding will be done via events.
But when super admin manage the application, how to load each client data to super admin panel, or let's say super admin want to make a announcement to al of his client, how to handle this in laravel so announcement data get synced to all database.
Maybe create a separate DB for SUPER-ADMIN, and that DB will be contains clients_table and other data needed to read/write data in clients-DB (data like client db name, user, password, for establish connection to his db etc.).
Alternatively - you can create special table `clients_announcments' in super-admin-db (or may be new db: common_clients_db) and use it for that (and read it from clients) - depends of how many clients you have and what efficency you need
If you create so "big" saas system with many DB, I also encourage you to hard separation between backend and frontend - this means laravel backend will only provide Restful API (NO html-css-js code - only pure php), and frotend client will be separate vue/angular/react project which will consume that API. Key words "micro-service architecture", "restful api"
I am working on a school project with multiyear database built in laravel.
My requirement is to feed data for every new academic year in some tables. I have a main (superadmin) db and separate school's db for every school. I need to connect to school db, n process is i have kept superadmin db details in .env file then it fetches particular school's db details and makes a connection to that school db through middleware.
My question is when i execute migration and seeding command it connects to superadmin db and performs respective operation. But i want to execute migration/seeding one by one for every school's db.
Add a extra entry into config/database.php For example mysql2
On each of your models specify the database it is related to. For example on your School Model
protected $connection = 'mysql2';
Now you can just run your seeder like you have 1 database , since the connection is specified on your models the correct database will be seeded.
you can run the command
php:artisan db:seed --class="className" --database=mysql2