Archery
Archery copied to clipboard
v1.9.1升级v1.10.0 migrate失败
重现步骤
1、按升级步骤执行src/init_sql/v1.10.0.sql 2、执行python manage.py migrate 报错 Running migrations: No migrations to apply. Your models in app(s): 'sql' have changes that are not yet reflected in a migration, and so won't be applied. Run 'manage.py makemigrations' to make new migrations, and then re-run 'manage.py migrate' to apply them. 3、按提示执行python manage.py makemigrations It is impossible to add a non-nullable field 'id' to config without specifying a default. This is because the database needs something to populate existing rows. Please select a fix:
- Provide a one-off default now (will be set on all existing rows with a null value for this column)
- Quit and manually define a default value in models.py.
预期外的结果
数据库合并失败,前台用户无法查询到已授权的数据库实例
日志文本
No response
版本
1.10.0
部署方式
Docker
是否还有其他可以辅助定位问题的信息?比如数据库版本等
No response
你选1, 然后把 migrations 打个包传上来看一下
这个版本升级不需要migrate
主要是前端看不到数据库实例了
你选1, 然后把 migrations 打个包传上来看一下
按提示选1,然后输入默认值timezone.now,执行makemigrations没报错,再执行manage.py migrate还是报错了ValueError: Found wrong number (0) of constraints for instance_account(instance_id, user, host)
这个版本升级不需要migrate
升级后前端用户看不到前期已配置的数据库实例,暂时只能回退1.9.1
看一下这里的改表语句
https://github.com/hhyo/Archery/blob/11176ae7b8b750324a0b26bb6e464643043049a1/src/init_sql/v1.10.0.sql#L2-L10
是否有执行不成功的情况?
看起来执行是成功的,这个改表预期就是清空所有数据的,可以试试把数据备份了重新导入一下
看起来执行是成功的,这个改表预期就是清空所有数据的,可以试试把数据备份了重新导入一下
所以新版本v1.10.0前端查询数据库实例是使用到了instance_account是吗? 因为目前这张表是空的,所以前端用户看不到数据库实例。
如果要手动导数据库实例信息到这张表,应该是从哪张表导入? 能麻烦提供下sql吗?
不好意思, 我这边可能理解有误, 你这边能不能尝试开一下 debug, 然后看一下错误信息, 看看是缺什么字段之类的, 看看这个方向有什么有价值的信息
不好意思, 我这边可能理解有误, 你这边能不能尝试开一下 debug, 然后看一下错误信息, 看看是缺什么字段之类的, 看看这个方向有什么有价值的信息
已开启DEBUG,暂未发现报错信息,前端用户仍查看不到已添加的数据库实例,回退v1.9.1可解决
2023/08/22 17:41:51 Waiting for: tcp://169.254.1.1:3306 2023/08/22 17:41:51 Waiting for: tcp://169.254.1.1:6379 2023/08/22 17:41:51 Connected to tcp://169.254.1.1:6379 2023/08/22 17:41:51 Connected to tcp://169.254.1.1:3306 切换python运行环境 修改重定向端口 启动nginx 收集所有的静态文件到STATIC_ROOT 2023-08-22 17:41:52,329 - archery.settings - INFO - 当前生效的外部认证方式:LDAP 2023-08-22 17:41:52,329 - archery.settings - INFO - 认证后端:('django_auth_ldap.backend.LDAPBackend', 'django.contrib.auth.backends.ModelBackend') import local settings failed, ignored 启动Django Q cluster Unlinking stale socket /tmp/supervisor.sock 启动服务 [2023-08-22 17:41:54 +0800] [34] [INFO] Starting gunicorn 20.0.4 [2023-08-22 17:41:54 +0800] [34] [INFO] Listening at: http://127.0.0.1:8888 (34) [2023-08-22 17:41:54 +0800] [34] [INFO] Using worker: sync [2023-08-22 17:41:54 +0800] [35] [INFO] Booting worker with pid: 35 [2023-08-22 17:41:54 +0800] [36] [INFO] Booting worker with pid: 36 [2023-08-22 17:41:54 +0800] [37] [INFO] Booting worker with pid: 37 [2023-08-22 17:41:55 +0800] [38] [INFO] Booting worker with pid: 38 2023-08-22 17:41:55,138 - archery.settings - INFO - 当前生效的外部认证方式:LDAP 2023-08-22 17:41:55,138 - archery.settings - INFO - 认证后端:('django_auth_ldap.backend.LDAPBackend', 'django.contrib.auth.backends.ModelBackend') 2023-08-22 17:41:55,218 - archery.settings - INFO - 当前生效的外部认证方式:LDAP 2023-08-22 17:41:55,218 - archery.settings - INFO - 认证后端:('django_auth_ldap.backend.LDAPBackend', 'django.contrib.auth.backends.ModelBackend') 2023-08-22 17:41:55,229 - archery.settings - INFO - 当前生效的外部认证方式:LDAP 2023-08-22 17:41:55,229 - archery.settings - INFO - 认证后端:('django_auth_ldap.backend.LDAPBackend', 'django.contrib.auth.backends.ModelBackend') 2023-08-22 17:41:55,297 - archery.settings - INFO - 当前生效的外部认证方式:LDAP 2023-08-22 17:41:55,297 - archery.settings - INFO - 认证后端:('django_auth_ldap.backend.LDAPBackend', 'django.contrib.auth.backends.ModelBackend')
那这边没有什么方法了, 需要你自己看看怎么回事了, 如果发现什么问题欢迎 pr, 1.9.1 有严重的 sql 注入问题, 有条件还是建议升级
@LeoQuote v1.10.0.sql 文件内变更instance_account 的存储过程有问题,由于表存在外键,需要先将外键删除,再删除索引,生成外键和唯一键。直接使用migrate 会导致表重新创建,数据丢失
查询异常报错,错误信息:(1054,"Unknown column django_q_schedule.cluster in field list”")
我看了一圈 init_sql 里面没这个字段,搜也没搜到。这个是什么情况阿?我是 1.8.5 到 1.10.0 执行了 1.9 与 1.10的 sql
@Yebolin python manage.py migrate
你版本太老了, django_q 有更新
@LeoQuote v1.10.0.sql 文件内变更instance_account 的存储过程有问题,由于表存在外键,需要先将外键删除,再删除索引,生成外键和唯一键。直接使用migrate 会导致表重新创建,数据丢失
有手动修复的办法吗? 目前我这边也是instance_account 表为空
# 进 pod 容器中, 手动执行数据库升级脚本. 当前 v1.10.0.sql 有问题, 需要先变更.
cp src/init_sql/v1.10.0.sql src/init_sql/v1.10.0.sql.default
-- https://github.com/hhyo/Archery/pull/2108
alter table instance_account
add db_name varchar(128) default '' not null comment '数据库名(mongodb)' after host;
-- custom: 删除外键
set @drop_fk_sql=(select concat('alter table instance_account drop foreign key ',constraint_name) from information_schema.table_constraints where table_schema=database() and table_name = 'instance_account' and constraint_type='foreign key');
prepare stmt from @drop_fk_sql;
execute stmt;
drop prepare stmt;
-- instance_account表调整唯一索引
set @drop_sql=(select concat('alter table instance_account drop index ', constraint_name) from information_schema.table_constraints where table_schema=database() and table_name='instance_account' and constraint_type='UNIQUE');
prepare stmt from @drop_sql;
execute stmt;
drop prepare stmt;
alter table instance_account add unique index uidx_instanceid_user_host_dbname(`instance_id`, `user`, `host`, `db_name`);
-- custom: 添加外键
alter table instance_account add constraint fk_account_sql_instance_id foreign key (instance_id) references sql_instance(id);
-- 增加 ssl 支持
ALTER TABLE sql_instance ADD is_ssl tinyint(1) DEFAULT 0 COMMENT '是否启用SSL';
source /opt/venv4archery/bin/activate
python manage.py dbshell < src/init_sql/v1.10.0.sql
python manage.py migrate
# 重启 archery 服务