Sorry, I can't ask a question on Changing table prefix and schema of ABP.IO so I am creating another.
In the documentation for ABP.IO it mentions changing table schemas (https://docs.abp.io/en/abp/latest/Entity-Framework-Core-Migrations), I've also looked at the git issue (https://github.com/abpframework/abp/issues/1429) referring to the addition of the AbpCommonDbProperties and the comment about adding it to the beginning of your program however I have tried several different things in all my projects and cannot seem to get it to work. The git comment indicates that these changes should work for all modules and having looked at the code I can see how the settings should be using it, but there must be something different about the Settings Module (or I think the error originates in the Localization module).
Running my HttpApi.Host project I get 'Microsoft.Data.SqlClient.SqlException (0x80131904): Invalid object name 'Settings'. I managed to set the default prefix during migration so my tables have all had their prefix removed, however I can't seem to get the host program to use the same prefix.
My solution contains a HttpApi.Host and IdentityServer project. Given the high-level of customisation that ABP has I'm a bit at a loss as to why this doesn't work easier (or in my case, at all).
The steps for my test are as follows.
abp new "DbTablePrefixTest" -t app -u mvc --tiered -d ef -csf true
Configure DefaultModelBuilderConfigurationOptions
protected override void OnModelCreating(ModelBuilder builder)
{
base.OnModelCreating(builder);
/* Include modules to your migration db context */
builder.ConfigurePermissionManagement(opt=>opt.TablePrefix=DbTablePrefixTestConsts.DbTablePrefix);
builder.ConfigureSettingManagement(opt => opt.TablePrefix = DbTablePrefixTestConsts.DbTablePrefix);
builder.ConfigureBackgroundJobs(opt => opt.TablePrefix = DbTablePrefixTestConsts.DbTablePrefix);
builder.ConfigureAuditLogging(opt => opt.TablePrefix = DbTablePrefixTestConsts.DbTablePrefix);
builder.ConfigureIdentity(opt => opt.TablePrefix = DbTablePrefixTestConsts.DbTablePrefix);
builder.ConfigureIdentityServer(opt => opt.TablePrefix = DbTablePrefixTestConsts.DbTablePrefix);
builder.ConfigureFeatureManagement(opt => opt.TablePrefix = DbTablePrefixTestConsts.DbTablePrefix);
builder.ConfigureTenantManagement(opt => opt.TablePrefix = DbTablePrefixTestConsts.DbTablePrefix);
/* Configure your own tables/entities inside the ConfigureDbTablePrefixTest method */
builder.ConfigureDbTablePrefixTest();
}
Delete Migrations folder under DbTablePrefixTest.EntityFrameworkCore.DbMigrations project.
dotnet ef migrations add "Inital"
dotnet ef database update
results are as follows:
Related
Is there a way to specify which provider use for a specific EF DbContext. For example:
DbContext1 -> MySQL
DbContext2 -> SQL Server
DBMS selection is done in the startup template. You can see here.
So, you can configure it in YourProjectNameEntityFrameworkCoreModule class.
Configure<AbpDbContextOptions>(options =>
{
options.UseSqlServer();
});
This code configures ALL dbcontexts in the application. You can configure each DbContext separately with the syntax given below:
Configure<AbpDbContextOptions>(options =>
{
options.Configure<MyProjectNameDbContext>(opts =>
{
opts.UseSqlServer();
});
options.Configure<SecondDbContext>(opts =>
{
opts.UseMySql();
});
});
Surely, you need to add Volo.Abp.EntityFrameworkCore.MySql package to your project before calling the UseMySql() extension method. See the documentation to learn to use other DBMSs.
I'm using realmjs DB in my react-native app where I have a schema settings. I want to change a property type of that schema from int to string. So I understand that I need to perform migration and I decided to perform a linear migration. For the migration I followed the example from Realm documentation and ended up doing something like below:
const schemaList = [schemaV1,schemaV2];
let nextSchemaIndex = Realm.schemaVersion(Realm.defaultPath);
while (nextSchemaIndex < schemaList.length) {
const migratedRealm = new Realm(schemaList[nextSchemaIndex++]);
migratedRealm.close();
}
export default new Realm(schemaList[schemaList.length - 1]);
schemaV1 is the old version of the db and schemaV2 is the latest version of the db after changes of property type. The schemaV2 also has a migration function like below:
if (oldRealm.schemaVersion < 1) {
const oldObjects = oldRealm.objects(TBL_MOBILE_SETTING);
const newObjects = newRealm.objects(TBL_MOBILE_SETTING);
for (let i = 0; i < oldObjects.length; i++) {
newObjects[i].module = oldObjects[i].module;
newObjects[i].setting = oldObjects[i].setting;
}
}
But at the end, when I'm trying to run the app, it's crashing with an error message that
Database migration is needed
Does it mean that the migration function in schemaV2 never runs? If so, how to make sure that all the migration functions are running properly? Or am I missing something else?
EDIT
I found that column type change is not allowed in RealmJS and I added a new column and tried to perform migration but still same error.
The problem was what I guessed. The migration function was not being called. I had to create an export const function and call the migration function in the index file cause it's the file which is called at the starting of the app.
I'm working on an application using Play and Slick. This app requires access to (at least) two databases and this is working fine when one is defined as default and other is named. Eg.,
db.default.driver = "com.mysql.jdbc.Driver"
db.default.url = "jdbc:mysql://localhost:3306/db1"
db.db2.driver = "com.mysql.jdbc.Driver"
db.db2.url = "jdbc:mysql://localhost:3306/db2"
I can then happily access each db as follows
DB.withSession { implicit session => ??? }
DB("db2").withSession { implicit session => ??? }
However, this doesn't really make sense as there is no reason DB1 should be the default. The DBs contain different types of data, neither is the default, both are important. What I would like is:
db.db1.driver = "com.mysql.jdbc.Driver"
db.db1.url = "jdbc:mysql://localhost:3306/db1"
db.db2.driver = "com.mysql.jdbc.Driver"
db.db2.url = "jdbc:mysql://localhost:3306/db2"
Play-scala barfs at this thought. It needs a default db driver and URL and it needs to be able to connect to it.
Anyone know anyway to change this behaviour or to trick play into thinking it has a default?
UPDATE
To be clear, I've greped my code to ensure that I'm not using DB.withSession anywhere. That is, every time I create a session I use DB("db1").withSession or DB("db2").withSession. However, when I run my test, I still get an exception:
Caused by: Configuration error: Configuration error[Slick error : jdbc driver not defined in application.conf for db.default.driver key]
Something somewhere is trying to load the default config.
Default is just a name, with some convenience functions (withSession and withTransaction without name), so, no you do not need to have a default connection if it does not fit your project.
I am using CakePHP 1.3 and trying to enable cache for view pages, cache system works fine and caches all pages. But when we add a new post (insert new record to database) or edit an old one (update a record of the table) CakePHP deletes all cached pages, not just the edited page!
app/config/core.php :
Cache::config('default', array('engine' => 'File','duration' => 8640000));
app/controllers/articles_controller.php :
var $helpers = array('Cache');
var $cacheAction = array(
'view' => array('duration' => 8640000),
'latest' => array('duration' => 8640000),
);
How can I tell Cake to delete just the cached version of changed page and not all cached pages?
This it actually pretty hard, so I can't just give you a piece of code to solve this. You need to edit the actual cake files in the lib folder that manage caching. Note: this is super not recommended by the cake people. However the lib/Cake/Cache/Engine/FileEngine.php is the file that has the operations of the file engine. You seem interested in the delete function:
/**
* Delete a key from the cache
*
* #param string $key Identifier for the data
* #return boolean True if the value was successfully deleted, false if it didn't exist or couldn't be removed
*/
public function delete($key) {
if ($this->_setKey($key) === false || !$this->_init) {
return false;
}
$path = $this->_File->getRealPath();
$this->_File = null;
//#codingStandardsIgnoreStart
return #unlink($path);
//#codingStandardsIgnoreEnd
}
Also, instead of editing the core cake files you could add your own file engine and use parted of the cake engine by moving the code and just extending the code there (that's totally cool in open source).
Its also possible that by reading the code used to implement the file caching engine you will find your actual solution. Good Luck.
Can Magento be integrated with CakePHP?
If my site is developed in CakePHP. Can I do the product module including shopping cart in Magento?
Yes, it can. For example:
require_once 'app/Mage.php';
umask(0);
Mage::app();
Mage::getSingleton('core/session', array('name'=>'frontend'));
$cart = Mage::helper('checkout/cart')->getCart()->getItemsCount();
echo 'Items count: ' . $cart;
Look at these articles:
http://www.exploremagento.com/magento/run-magento-code-outside-of-magento.php
http://blog.chapagain.com.np/magento-how-to-run-magento-code-in-an-external-website/
can make the Mage class working for me in pure php code with the above example. But you know Cakephp has its own routing mechanism. I have magento installed in the root and trying to add another application built with cakephp - that application has its own data structure & database (mainly be used for custom reporting and some tracking stuffs) but will share some data from magento (that is the main site)
I managed to do a hack (and there where no other way to do that).
The hack is you need to put the "function __()" inside in line 93 of Magento app/code/core/Mage/Core/functions.php
if (!function_exists('__')) {
function _ () { .... }
}
and you need to do the same for "DS" in app/Mage.php line 23
if(!defined('DS')) {}
then you can just use the Mage class and do all the operation to Megento.