@ -43,9 +43,9 @@ export default async function(ctx: NcUpgraderCtx) {
await projectBuilder . init ( ) ;
await projectBuilder . init ( ) ;
}
}
await migrateUsers ( ncMeta ) ;
const usersObj = await migrateUsers ( ncMeta ) ;
const projectsObj = await migrateProjects ( ncMeta ) ;
const projectsObj = await migrateProjects ( ncMeta ) ;
await migrateProjectUsers ( ncMeta ) ;
await migrateProjectUsers ( projectsObj , usersObj , ncMeta ) ;
const migrationCtx = await migrateProjectModels ( ncMeta ) ;
const migrationCtx = await migrateProjectModels ( ncMeta ) ;
await migrateUIAcl ( migrationCtx , ncMeta ) ;
await migrateUIAcl ( migrationCtx , ncMeta ) ;
@ -58,12 +58,13 @@ export default async function(ctx: NcUpgraderCtx) {
async function migrateUsers ( ncMeta = Noco . ncMeta ) {
async function migrateUsers ( ncMeta = Noco . ncMeta ) {
const users = await ncMeta . metaList ( null , null , 'xc_users' ) ;
const users = await ncMeta . metaList ( null , null , 'xc_users' ) ;
const userList : User [ ] = [ ] ;
const userObj : { [ id : string ] : User } = { } ;
for ( const user of users ) {
for ( const user of users ) {
userList . push ( await User . insert ( user , ncMeta ) ) ;
const user1 = await User . insert ( user , ncMeta ) ;
userObj [ user1 . id ] = user1 ;
}
}
return userList ;
return userObj ;
}
}
async function migrateProjects (
async function migrateProjects (
@ -101,10 +102,20 @@ async function migrateProjects(
return projectsObj ;
return projectsObj ;
}
}
async function migrateProjectUsers ( ncMeta = Noco . ncMeta ) {
async function migrateProjectUsers (
projectsObj : { [ p : string ] : Project } ,
usersObj : { [ p : string ] : User } ,
ncMeta = Noco . ncMeta
) {
const projectUsers = await ncMeta . metaList ( null , null , 'nc_projects_users' ) ;
const projectUsers = await ncMeta . metaList ( null , null , 'nc_projects_users' ) ;
for ( const projectUser of projectUsers ) {
for ( const projectUser of projectUsers ) {
// skip if project is missing
if ( ! ( projectUser . project_id in projectsObj ) ) continue ;
// skip if user is missing
if ( ! ( projectUser . user_id in usersObj ) ) continue ;
await ProjectUser . insert (
await ProjectUser . insert (
{
{
project_id : projectUser.project_id ,
project_id : projectUser.project_id ,
@ -199,6 +210,7 @@ interface Formulav1 {
formula : {
formula : {
value : string ;
value : string ;
tree : any ;
tree : any ;
error : string [ ] | string ;
} ;
} ;
}
}
@ -649,10 +661,20 @@ async function migrateProjectModels(
const colBody : any = {
const colBody : any = {
_cn : columnMeta._cn
_cn : columnMeta._cn
} ;
} ;
colBody . formula = await substituteColumnAliasWithIdInFormula (
if ( columnMeta ? . formula ? . error ? . length ) {
columnMeta . formula . value ,
colBody . error = Array . isArray ( columnMeta . formula . error )
await model . getColumns ( ncMeta )
? columnMeta . formula . error . join ( ',' )
) ;
: columnMeta . formula . error ;
} else {
try {
colBody . formula = await substituteColumnAliasWithIdInFormula (
columnMeta . formula . value ,
await model . getColumns ( ncMeta )
) ;
} catch {
colBody . error = 'Invalid formula' ;
}
}
colBody . formula_raw = columnMeta . formula . value ;
colBody . formula_raw = columnMeta . formula . value ;
const column = await Column . insert (
const column = await Column . insert (
{
{
@ -1084,11 +1106,15 @@ async function migrateSharedViews(ctx: MigrateCtxV1, ncMeta: any) {
for ( const sharedView of sharedViews ) {
for ( const sharedView of sharedViews ) {
let fk_view_id ;
let fk_view_id ;
// if missing view name or model name skip the shared view migration
if ( ! sharedView . view_name || ! sharedView . model_name ) continue ;
if ( sharedView . view_type !== 'table' && sharedView . view_type !== 'view' ) {
if ( sharedView . view_type !== 'table' && sharedView . view_type !== 'view' ) {
fk_view_id =
fk_view_id =
ctx . objViewRef [ sharedView . project_id ] [ sharedView . model_name ] [
ctx . objViewRef [ sharedView . project_id ] [ sharedView . model_name ] [
sharedView . view_name
sharedView . view_name
] . id ;
] ? . id ;
} else {
} else {
fk_view_id =
fk_view_id =
ctx . objViewRef [ sharedView . project_id ] [ sharedView . model_name ] [
ctx . objViewRef [ sharedView . project_id ] [ sharedView . model_name ] [
@ -1096,9 +1122,12 @@ async function migrateSharedViews(ctx: MigrateCtxV1, ncMeta: any) {
] . id ||
] . id ||
ctx . objViewRef [ sharedView . project_id ] [ sharedView . model_name ] [
ctx . objViewRef [ sharedView . project_id ] [ sharedView . model_name ] [
sharedView . model_name
sharedView . model_name
] . id ;
] ? . id ;
}
}
// if view id missing skip shared view migration
if ( ! fk_view_id ) continue ;
await View . update (
await View . update (
fk_view_id ,
fk_view_id ,
{
{