# |
Mar 29th 2019, 12:58 |
admad |
i can't remember off top of my head what's the method which handles that |
# |
Mar 29th 2019, 12:58 |
val |
@spriz nope, no subdomains |
# |
Mar 29th 2019, 12:58 |
admad |
@val right, you can prefix the db names to tables/aliases |
# |
Mar 29th 2019, 12:58 |
spriz |
@val do each customer not have their own subdomain or something like that? In that case you’d need to only get that single subdomain |
# |
Mar 29th 2019, 12:56 |
val |
@admad well, in cake 2.x this can be done by prefixing the table name with the schema name. F.ex. `$DataSource->buildStatement([..., 'table' => 'db_1.orders_table'], $this)`. |
# |
Mar 29th 2019, 12:49 |
admad |
yeah you can't stuff like that when using an abstraction layer |
# |
Mar 29th 2019, 12:47 |
val |
`db_main`, `db_1`, `db_2` are different databases. |
# |
Mar 29th 2019, 12:46 |
val |
A very simplified example in MySQL: `USE db_main; SELECT * from db_main.customers; SELECT * from db_1.orders_table; SELECT * from db_2.orders_table;` |
# |
Mar 29th 2019, 12:46 |
admad |
db name is specified when PDO object is created |
# |
Mar 29th 2019, 12:44 |
val |
@admad so, technically the database connection is the same, but the schema name is not |
# |
Mar 29th 2019, 12:43 |
val |
@admad iterating 1000 customers and creating 1000 connections is not viable. We do switch the schema name on the fly in 2.x but in a quite a hacky way. So, I hoped it would be easier in 3.x. |
# |
Mar 29th 2019, 12:39 |
val |
@spriz I saw that article. That would not work for us. |
# |
Mar 29th 2019, 12:39 |
admad |
if connection hasn't already been made than just update the connection config |
# |
Mar 29th 2019, 12:38 |
admad |
@val you can't change db of active connection. you need to change and reconnect so practically same as making new connection |
# |
Mar 29th 2019, 12:38 |
spriz |
It’s from 2015 but I think it’s still applicable with minor adjustments |
# |
Mar 29th 2019, 12:37 |
spriz |
I’d check http://mark-story.com/posts/view/using-cakephp-and-a-horizontally-sharded-database :slightly_smiling_face: |
# |
Mar 29th 2019, 12:37 |
val |
@spriz what simpler solution? @admad ok, how the connection can switch from one schema from another without creating a new connection? |
# |
Mar 29th 2019, 12:35 |
spriz |
I’ve previously just used multiple database connections though |
# |
Mar 29th 2019, 12:35 |
admad |
database name name is set in connection, models/tables know nothign abotu it |
# |
Mar 29th 2019, 12:35 |
spriz |
There’s been quite a lot of talk about multi tenancy applications like that in cakephp, I think there is a simpler solution to that @val :slightly_smiling_face: |
# |
Mar 29th 2019, 12:35 |
val |
@admad by scheama I mean a database with tables |
# |
Mar 29th 2019, 12:34 |
admad |
@val you by schema you mean table? |
# |
Mar 29th 2019, 12:34 |
val |
@spriz more or less the same environment. Because there are thousands of customers. @admad nope. We use MySQL. |
# |
Mar 29th 2019, 12:33 |
spriz |
And why is it too expensive to create a new connection? |
# |
Mar 29th 2019, 12:33 |
admad |
@val are you referring to postgres schema? |
# |
Mar 29th 2019, 12:33 |
spriz |
Hmm, and it’s the same app environment for all customers? |
# |
Mar 29th 2019, 12:28 |
val |
I wonder how would it be possible to set the schema name before the model is created. Logically, model factory seems to be a good place for that. |
# |
Mar 29th 2019, 12:24 |
val |
> Hi, is there a quick way in cake 3.x to switch to a different database schema without creating a new database connection? The use case is when each customer has its own database, the schemas are identical for each customer and cake app needs to retrieve data from multiple databases (from identical table of the customer database). Or simply to switch from one customer database to another. Creating new connections is too expensive. |
# |
Mar 29th 2019, 12:22 |
spriz |
What are you trying to accomplish @val? |
# |
Mar 29th 2019, 12:22 |
slackebot2 |
!xy problem |
# |
Mar 29th 2019, 12:22 |
slackebot2 |
Command sent from Slack by spriz: |
# |
Mar 29th 2019, 12:22 |
spriz |
I believe so, not completely sure though. This could sound like a XY problem though |
# |
Mar 29th 2019, 12:21 |
val |
IndexRegistry is a factory? |
# |
Mar 29th 2019, 12:20 |
spriz |
that’s a cakephp elasticsearch integration using these model factories |
# |
Mar 29th 2019, 12:20 |
spriz |
specifically https://github.com/cakephp/elastic-search/blob/b9d434c0fce6250a8acb616f7be00d599e276803/src/IndexRegistry.php AFAIK :slightly_smiling_face: |
# |
Mar 29th 2019, 12:20 |
val |
@spriz what's that? |
# |
Mar 29th 2019, 12:19 |
spriz |
@val I’d imagine it could be https://github.com/cakephp/elastic-search/tree/master/src ? |
# |
Mar 29th 2019, 12:18 |
val |
The cookbook briefly mentions the model factory - https://book.cakephp.org/3.0/en/controllers.html#loading-additional-models. Could anyone provide an example or a better explanation how to build my own model factory? |
# |
Mar 29th 2019, 12:15 |
spriz |
People tend to forget that developing software is not really about the initial cost but also the year-to-year maintenance, which often is the same or higher than the cost of initially building it |
# |
Mar 29th 2019, 12:14 |
spriz |
@acosonic as an outsider it really seems like you’re working with someone that do not truly understand the maintenance cost of software :cold_sweat: |
# |
Mar 29th 2019, 10:19 |
acosonic |
Well, now they have decided to make order in backend system, it might be good idea to work on migration later |