New Tenancy 1.x Laravel How Insert Data after create DB - laravel

I am trying to test the new version of Tenancy 1.X in laravel, but I don't understand how to insert data after creating a Tenant database
I mean in the same function
I understand that the function in charge of creating is:
Created :: class,
Someone use this version?

I'm working on that now with no less issues and unknownledge but step by step I'm resolve my requirements. What exactly are you trying to do? Insert data from tenant domain or from another, for example main app.
main app:
Tenancy::setTenant($tenant)
App\Modals\Tenant\User::create(....);
App\Modals\Tenant\User::update(....);

Related

How to use spatie / laravel-multitenancy with single database?

I want to convert my existing app to multi-tenant and don't want to use multiple databases. just read that the given package is allowing that.
https://github.com/spatie/laravel-multitenancy
I have read the single database documentation here: https://spatie.be/docs/laravel-multitenancy/v2/installation/using-a-single-database
But what's next ??
Let's say right now users are storing into users' tables, and by using this package I want to store users tenant-specific.
I don't found the real example anywhere. so better if anyone already implemented Spatie Multi-tenant by using a single Database, please help me here.
Thanks in advance.
Although spatie/laravel-multitenancy supporting single databases, it doesn't come with query scopes (and seems like there are no plans to add them, as you can see here: https://github.com/spatie/laravel-multitenancy/issues/124), so you would need to create them manually.
So, you need to:
add the tenant_id to your tenant-specific tables
add an observer to save the tenant_id when creating a new register in the table
add a global query scope to always filter the data using the current tenant id
You can see something similar in this video: https://www.youtube.com/watch?v=nCiNqboYFVQ
The difference is that you will use the current tenant returned by spatie/laravel-multitenancy instead of the logged user id to get the tenant data.
If you want a package that already brings the query scopes ready to use, you may try Tenancy for Laravel: https://tenancyforlaravel.com/docs/v3/single-database-tenancy
Or, if your application has a very simple multi-tenancy strategy (for example, the tenant is the logged user or his team) you can just create some query scopes without the need to use packages, exactly as the video above teaches, as it is much more simple to identify the tenant by the user_id or team_id, even in terminal commands and queue jobs (but seems that is not your case, as you need the users to belongs to a tenant).
I hope it helps you to select the correct package and strategy for your project.

How to use existing dynamo db with AWS Amplify and graphql

We have existing database in dynamodb for our application. For one of our new React app, we want to use AWS Amplify and we are trying to use the existing tables.
I created a skeleton project and went to backend AWS AppSync console -> Data Sources and map the existing table to it. And I added that table definition to my schema.graphql in my react app. When I do an amplify push, I see it creating a new table in dynamodb, rather than pointing to the existing db.
I also tried to map one of the tables in AppSync Console, and did amplify pull from local project, assuming that will add the definition of the table in my local schema.graphql but that did not happen either. It did not pull down the details of the newly mapped data source from backend app sync console.
My existing db has lot of data and is shared with other applications as well. I do not want to create a new table.
Can you pls suggest how to accomplish this?
Also we have existing lamdba functions which we would want to leverage into this new Amplify project as well. Could you pls suggest pointers for this as well.
Any help is much appreciated!
Line 22 in the file below shows how the table name is constructed when the graphql.schema transformer runs; that is - the name is derived from the GraphQLAPI ID and this seems to be a one way process.
TableName: joinWithEnv('-', [SyncResourceIDs.syncTableName, Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId')]),
https://github.com/aws-amplify/amplify-cli/blob/e1e07b245db0963c4655e646c53e7615febe2930/packages/graphql-transformer-core/src/util/syncUtils.ts
The only option then would be to try and patch the resulting CFN script.
You can use amplify import storage to import existing DynamoDB tables or S3 buckets.
more here: https://docs.amplify.aws/cli/storage/import/
Also look at
Re-use existing AppSync GraphQL API - it might help with reusing lambda functions, if they are wrapped by an API.

The place where to execute custom code while migration

Guys please advice. I'm release new version of software and there were some braking changes, to order properly update from previous version i need to execute custom code on applying certain migration.
Update steps are:
1. Get all records from one table
2. Foreach thought them and create appropriate record in other tables
I prefer to use my "Manager" from business logic layer(core)
I don't know yet how to implements this. Please give me advice or code sample would be better.
So far I see 3 places where I can put these logic.
1. Migration file itself. in EF layer.
2. Migrator project.
3. Seed file in EF layer.
According to #Avin Kavish recommendation I've created method in Migrator project with additional flag "-migrateToV2" and create method which use my manager from core to update data properly. Thanks.

InnerException {"Invalid object name 'dbo.Users'"}

I am currently trying to setup an ASP.Net MVC 3 Application for the first time. I know what I am doing with Ruby on Rails but completely lost with ASP.Net. I would like the app to create the database but not sure what I am doing wrong. I have an empty Database build called ssDB. I have setup the connectionStrings and built out the Model classes. According to everything I have read thus for, when I go to the run the App it should create the database but it doesn't look that way.
The Abbreviated Error I get is:
InnerException: System.Data.SqlClient.SqlException
Message=Invalid object name 'dbo.Users'.
Source=.Net SqlClient Data Provider
ErrorCode=-2146232060
Class=16
LineNumber=1
Number=208
Procedure=""
Server=TESTSVR01
State=1
I have an empty Database build called ssDB
You have created an empty database with no tables. Since there is a database EF assumes tables are also created. Hence it will not proceed to create the tables.
You can drop the database and allow EF to create the database and the tables.
I also experienced the same issue while using Database first approach. Connection string in my service's/service's host web.config was incorrect. I corrected the connection string and it worked.

Database migrations in Grails

Suppose I have a database containing 3 tables in a grails application:
User
Activity
Friend
User table table has one to many relation to Activity and Friend tables so in User table I have:
static hasMany = [activies: Activity, friends: Friend]
and in Friend and Activity I have:
static belongsTo User.
Application is deployed and lets says thousands of customers have registered. Now changes are made in the database: Table Activity is dropped. A table Journal is created which is on the many sides of the User table. The User table has a new column added and this column cannot be null. An old column in Friend table is deleted that was also defined as not null.
So given above scenario and assume using MySQL what needs to be done to make above changes without deleting existing customers data and safely add the new table to existing customers?
Ruby on Rails comes with ActiveRecord for database migrations. Does Grails comes with something like this out of the box?
Currently in development when I run my grails application after adding a new not null column to a table, I get column cannot be null exception thrown unless I delete that table in the database before running grails application which would recreate the table if not exists. Obviously once the application is deployed I will not have the luxury to delete the table.
Unfortunately, the current version of Grails doesn't come with database migration. However, there is a plugin for Liquibase which makes migrations possible.
The next version of Grails (1.4, planned for Q1 2011) will supposedly contain a built-in migration tool, which I am very much looking forward to.
Note: I haven't used the Liquibase plugin, so I don't have any firsthand experience with it. I have seen numerous blog posts describing its use, however, and I'm probably going to use it in my next Grails project if 1.4 isn't out by then.

Resources