# Setting up persistence model in modeling 4.0

**URL:** <https://community.holistics.io/t/setting-up-persistence-model-in-modeling-4-0/1721>\
**Category:** Ask the Community\
**Tags:** data-model, aml, performance\
**Created:** [October 26, 2023, 7:51pm UTC](https://community.holistics.io/t/setting-up-persistence-model-in-modeling-4-0/1721 "2023-10-26T19:51:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Matt\_Stone](https://community.holistics.io/user_avatar/community.holistics.io/matt_stone/32/1532_2.png) [@Matt\_Stone](https://community.holistics.io/u/Matt_Stone)\
**Post date:** [October 26, 2023, 7:51pm UTC](https://community.holistics.io/t/setting-up-persistence-model-in-modeling-4-0/1721/1 "2023-10-26T19:51:33Z")

</div>

I’m trying to setup a persistent model for the first time in a postgres db integration. I have been following instructions from these references:

- [Query Model | Holistics Docs (4.0)](https://docs.holistics.io/docs/transform-models#enable-storage-settings-model-persistence-for-holistics-40)
- [Model Storage Settings | Holistics Docs (4.0)](https://docs.holistics.io/docs/storage-settings)
- [Query Model Persistence | Holistics Docs (4.0)](https://docs.holistics.io/as-code/persistence#schedule-trigger)

I don’t see evidence that holistics is attempting to make the persistent model, so I must have something wrong.

user for datasource: `holistics_user`  
schema for persistence: `holistics_persistence`

## Snip from the persistent model.aml file:

```aml
Model p_clarus_c_survey_question_answer {
  type: 'query'
  label: "p_Survey Questions and Answers"
  description: 'Full list of questions with answers for surveys. This is the base for distinct question types'
  data_source_name: 'compass'
  owner: 'mstone@thebrightlink.com'
  query: @sql
    select r.id as r_id,
      c.name as client,
      r.created,
      r.type as survey_type,
      t.question,
      t.answer
    from {{ #clarus_c_survey_response_light r }}
    JOIN
      {{ #public_client c }} ON c.slug = r.client,
      lateral jsonb_each_text(r.custom_data -> 'survey'::text) t(question, answer);;

  models: [
    clarus_c_survey_response_light,
    public_client
  ]

  persistence: FullPersistence {
    schema: 'holistics_persistence'
  }  

  dimension r_id {
    label: "R Id"
    type: "number"
    hidden: true
    definition: @sql {{ #SOURCE.r_id }};;
  }
<snip>
}

```

## /schedules.aml

```aml
// import './common_models/clarus/value_survey/1_base_models/clarus_c_survey_response_p_question_answer.model.aml' {p_clarus_c_survey_question_answer}

const schedules = [
  // Schedule orders model to run every 15 minutes
  Schedule { models: [p_clarus_c_survey_question_answer], cron: '*/15 * * * *' }
]

```

The import command is commented because I’m getting an error from the online editor stating:  
`[Syntax Error] Cannot find name 'import'. (2:1)`

When I publish the dataset, I get the CTE in the executed query:

```sql
WITH "p_clarus_c_survey_question_answer" AS (
  select r.id as r_id,
    c.name as client,
    r.created,
    r.type as survey_type,
    t.question,
    t.answer
  from (
    WITH "clarus_c_survey_response_light" AS (
      SELECT
        c.name as client,
        r.id,
        r.created,
        r.type,
        r.user_id,
        r.client_id,
        r.user_uuid,
        r.custom_data
      FROM public.clarus_survey_response r
      join (
        SELECT
          "public_client"."id" AS "id",
          "public_client"."slug" AS "slug",
          "public_client"."name" AS "name",
          "public_client"."type" AS "type",
          "public_client"."status" AS "status",
          "public_client"."custom_data" AS "custom_data"
        FROM
          "public"."client" "public_client"
      ) AS "c" on c.slug = r.client
    )
    SELECT
      "clarus_c_survey_response_light"."id" AS "id",
      "clarus_c_survey_response_light"."created" AS "created",
      "clarus_c_survey_response_light"."type" AS "type",
      "clarus_c_survey_response_light"."user_id" AS "user_id",
      "clarus_c_survey_response_light"."client_id" AS "client_id",
      "clarus_c_survey_response_light"."user_uuid" AS "user_uuid",
      "clarus_c_survey_response_light"."custom_data" AS "custom_data",
      "clarus_c_survey_response_light"."client" AS "client"
    FROM
      "clarus_c_survey_response_light"
  ) AS "r"
  JOIN
    (
      SELECT
        "public_client"."id" AS "id",
        "public_client"."slug" AS "slug",
        "public_client"."name" AS "name",
        "public_client"."type" AS "type",
        "public_client"."status" AS "status",
        "public_client"."custom_data" AS "custom_data"
      FROM
        "public"."client" "public_client"
    ) AS "c" ON c.slug = r.client,
    lateral jsonb_each_text(r.custom_data -> 'survey'::text) t(question, answer)
)
SELECT
  "public_client"."type" AS "pc_t_f101f2",
  COUNT("p_clarus_c_survey_question_answer"."created") AS "c_pccsqa_c_388ce0"
FROM
  "p_clarus_c_survey_question_answer"
  LEFT JOIN "public"."client" "public_client" ON "p_clarus_c_survey_question_answer"."client" = "public_client"."slug"
GROUP BY
  1
ORDER BY
  2 DESC
LIMIT 100000

```

Is the import directive required?

In psql, I don’t see any footprint from holistics in the new schema.

I’ve waited for the 15m boundary for cron to run and still no dice. How do I debug where it’s failing?

---

<div class="post-metadata">

**Author:** ![Tien\_Truong\_Tran](https://community.holistics.io/user_avatar/community.holistics.io/tien_truong_tran/32/1352_2.png) [@Tien\_Truong\_Tran](https://community.holistics.io/u/Tien_Truong_Tran)\
**Post date:** [October 27, 2023, 9:01am UTC](https://community.holistics.io/t/setting-up-persistence-model-in-modeling-4-0/1721/2 "2023-10-27T09:01:18Z")

</div>

Hi @Matt_Stone,

I’m Tien from the Holistics Support Team.  
Thank you for reaching out and bringing this issue to our attention.

After some investigations, it has come to our notice that there is an issue on our end causing the data model persistence feature to fail. Please rest assured that our engineering team is actively working on resolving this problem.

As for debugging this flow, we do not have a UI mode available for users. However, I want to assure you that I have escalated this matter to our product team. We are prioritizing the development of a feature that will allow users to easily debug this flow.

Best regards,

---

<div class="post-metadata">

**Author:** ![Tien\_Truong\_Tran](https://community.holistics.io/user_avatar/community.holistics.io/tien_truong_tran/32/1352_2.png) [@Tien\_Truong\_Tran](https://community.holistics.io/u/Tien_Truong_Tran)\
**Post date:** [October 27, 2023, 1:13pm UTC](https://community.holistics.io/t/setting-up-persistence-model-in-modeling-4-0/1721/3 "2023-10-27T13:13:18Z")

</div>

Hello @Matt_Stone,

I’ve just received an update from our engineering team, and unfortunately, the fix won’t be available until Monday. I apologize for any inconvenience this may cause.

In the meantime, if you have any additional questions, please don’t hesitate to reach out.

Best regards,

---

<div class="post-metadata">

**Author:** ![Matt\_Stone](https://community.holistics.io/user_avatar/community.holistics.io/matt_stone/32/1532_2.png) [@Matt\_Stone](https://community.holistics.io/u/Matt_Stone)\
**Post date:** [October 27, 2023, 2:28pm UTC](https://community.holistics.io/t/setting-up-persistence-model-in-modeling-4-0/1721/4 "2023-10-27T14:28:52Z")

</div>

Thanks @Tien_Truong_Tran I’ll stand by until early next week and check in on it again. I’m guessing I got the config correct. 🙂

Should I be concerned about the import statement not working? Is that required or expected in the `schedules.aml` ?

---

<div class="post-metadata">

**Author:** ![Tien\_Truong\_Tran](https://community.holistics.io/user_avatar/community.holistics.io/tien_truong_tran/32/1352_2.png) [@Tien\_Truong\_Tran](https://community.holistics.io/u/Tien_Truong_Tran)\
**Post date:** [October 30, 2023, 1:49am UTC](https://community.holistics.io/t/setting-up-persistence-model-in-modeling-4-0/1721/5 "2023-10-30T01:49:27Z")

</div>

Hi @Matt_Stone,

I hope you had a wonderful weekend!

Regarding the import statement, there’s no need for the import statement in AML 2.0.  
To confirm your AML version, simply check the file `version.aml` in the root directory. For AML 2.0, the file’s content should be `const AML_VERSION = '2.0'`.

You can check the different between AML 1.0 and 2.0 in our community post [here](https://community2.holistics.io/t/launched-aml-2-0-introduce-aml-modules-and-important-aml-syntax-changes/895).

Best regards

---

<div class="post-metadata">

**Author:** ![Tien\_Truong\_Tran](https://community.holistics.io/user_avatar/community.holistics.io/tien_truong_tran/32/1352_2.png) [@Tien\_Truong\_Tran](https://community.holistics.io/u/Tien_Truong_Tran)\
**Post date:** [October 30, 2023, 4:14am UTC](https://community.holistics.io/t/setting-up-persistence-model-in-modeling-4-0/1721/6 "2023-10-30T04:14:56Z")

</div>

Hi @Matt_Stone,

We have just released a new version to resolve the issue concerning data model persistence.  
Could you help try it again to see if it works correctly on your side?

Best regards,

---

<div class="post-metadata">

**Author:** ![Matt\_Stone](https://community.holistics.io/user_avatar/community.holistics.io/matt_stone/32/1532_2.png) [@Matt\_Stone](https://community.holistics.io/u/Matt_Stone)\
**Post date:** [November 2, 2023, 5:31pm UTC](https://community.holistics.io/t/setting-up-persistence-model-in-modeling-4-0/1721/7 "2023-11-02T17:31:26Z")

</div>

that did the trick. thanks!

---

<div class="post-metadata">

**Author:** ![Tien\_Truong\_Tran](https://community.holistics.io/user_avatar/community.holistics.io/tien_truong_tran/32/1352_2.png) [@Tien\_Truong\_Tran](https://community.holistics.io/u/Tien_Truong_Tran)\
**Post date:** [November 3, 2023, 7:34am UTC](https://community.holistics.io/t/setting-up-persistence-model-in-modeling-4-0/1721/8 "2023-11-03T07:34:01Z")

</div>

Hi @Matt_Stone

Great to hear that the issue has been resolved!  
If you have any more questions, please don’t hesitate to reach out here or via our support email at [support@holistics.io](mailto:support@holistics.io).

Best regards,
