用例
要设置开发环境,需要应用程序数据库的mysql转储。转储来源是生产数据库。
问题
我不想给任何人转储,因为它包含(哈希)用户密码。
解决思路
在允许访问转储之前,在服务器端替换所有用户密码(所有用户用于开发目的的一个密码都可以)。
环境
有什么办法聪明地解决这个问题吗?
示例转储(仅用户表)
# ************************************************************
# Sequel Pro SQL dump
# Version 4541
#
# http://www.sequelpro.com/
# https://github.com/sequelpro/sequelpro
#
# Host: 127.0.0.1 (MySQL 5.7.12)
# Datenbank: app
# Erstellt am: 2017-01-04 14:22:35 +0000
# ************************************************************
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;
# Export von Tabelle users
# ------------------------------------------------------------
DROP TABLE IF EXISTS `users`;
CREATE TABLE `users` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`role` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`tenant_id` int(10) unsigned DEFAULT NULL,
`name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,
`password` varchar(60) COLLATE utf8_unicode_ci NOT NULL,
`remember_token` varchar(100) COLLATE utf8_unicode_ci DEFAULT NULL,
`created_at` timestamp NULL DEFAULT NULL,
`updated_at` timestamp NULL DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `users_email_tenant_id_role_unique` (`email`,`tenant_id`,`role`),
KEY `users_tenant_id_index` (`tenant_id`),
CONSTRAINT `users_tenant_id_foreign` FOREIGN KEY (`tenant_id`) REFERENCES `tenants` (`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
LOCK TABLES `users` WRITE;
/*!40000 ALTER TABLE `users` DISABLE KEYS */;
INSERT INTO `users` (`id`, `role`, `tenant_id`, `name`, `email`, `password`, `remember_token`, `created_at`, `updated_at`)
VALUES
(1,'admin',1,'appadmin','admin@example.com','123$15$g4qKHcS7zHercuNJobfFxOTWGoW7YN.tphFdddGIIEXkrkE8Etxxx',NULL,'2017-01-04 14:19:04','2017-01-04 14:19:04');
/*!40000 ALTER TABLE `users` ENABLE KEYS */;
UNLOCK TABLES;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;
/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;发布于 2017-01-13 10:23:52
我建议这样做:
create table users_tmp like users;
insert into users_tmp select * from users;
update users_tmp set password='whatever';然后进口后
rename table users_tmp to users;发布于 2017-01-12 16:17:32
创建一个简单的命令来替换User表中的所有(非管理员)电子邮件地址和密码,然后转储数据库。下面的密码保护命令更改不使用给定域的所有电子邮件地址,然后更改所有帐户的密码。在fire方法的末尾,添加artisan命令以转储数据库。(假设您已经有了用于此的包)。
class RelacePasswordsAndEmailsCommand extends Command {
protected $name = 'mycommand/safe_user_dump';
protected $description = 'Changes all email addresses and passwords for a safe dump';
public function __construct() {
parent::__construct();
}
public function fire() {
if ($this->confirm('WARNING! This will change all email addresses and passwords in the database. Do you wish to continue? [yes|no]')) {
$password = $this->secret('What is the password?');
if ( $password === 'mysecretpassword' ) {
$emails = DB::table('users')
->where(function ($q) {
return $q->where('email', 'NOT LIKE', '%@example.com');
})->lists('id');
foreach ($emails as $id ) {
DB::table('users')->where('id', $id)->update(['email' => 'user' . $id . '@example.com']);
}
DB::table('users')->update(['password' => 'myhashpassword'])
$this->info( count($emails) . ' email addresses and passwords changed.');
# Add your database dump command here
} else {
$this->info('The password was incorrect.');
}
}
}
}发布于 2017-01-15 00:02:08
用例:
https://stackoverflow.com/questions/41465842
复制相似问题