Skip to content

feat: add template version creator #3001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Jul 15, 2022

Conversation

AbhineetJain
Copy link
Contributor

This PR adds a created_by field to the template version table and returns the relevant data with the API calls.

Subtasks

  • add a created_by field to the template version table
  • populate the default value of the field from the created_by field from the corresponding template
  • populate the field on insertion
  • return the field via the API

This will enable us to show the template version history (who created it and when) on the Template page for #2876.

Example API Call

Request

http://localhost:8080/api/v2/templateversions/be409505-f1cd-40ac-8c2d-364c27469681

Response

{
    "id": "be409505-f1cd-40ac-8c2d-364c27469681",
    "template_id": "790457b4-bd93-43dc-9c76-cf43c7251448",
    "organization_id": "8668a031-d228-4773-abb2-bc8ac2f39716",
    "created_at": "2022-07-14T16:43:45.993399969Z",
    "updated_at": "0001-01-01T00:00:00Z",
    "name": "elastic_leavitt4",
    "job": {
        "id": "bd08dbcf-5274-49b7-bfe5-a1c4ee259cd5",
        "created_at": "2022-07-14T16:43:45.993396474Z",
        "started_at": "2022-07-14T16:43:46.172760057Z",
        "completed_at": "2022-07-14T16:43:52.543660466Z",
        "status": "succeeded",
        "worker_id": "3f74d616-df83-4557-9fd0-d31a863ed0d8",
        "storage_source": "6c621616837cca443cf54c9445c8986527e24ee12a09c3c51ffa98c3abf743be"
    },
    "readme": "---\nname: Develop code-server in Docker\ndescription: Run code-server in a Docker development environment\ntags: [local, docker]\n---\n\n# code-server in Docker\n\n## Getting started\n\nRun `coder templates init` and select this template. Follow the instructions that appear.\n\n## Supported Parameters\n\nYou can create a file containing parameters and pass the argument\n`--parameter-file` to `coder templates create`.\nSee `params.sample.yaml` for more information.\n\nThis template has the following predefined parameters:\n\n- `docker_host`: Path to (or address of) the Docker socket.\n  \u003e You can determine the correct value for this by runnning\n  \u003e `docker context ls`.\n- `docker_arch`: Architecture of the host running Docker.\n  This can be `amd64`, `arm64`, or `armv7`.\n",
    "created_by_id": "6d17ede3-bf5d-4bb9-b1c3-5dbcf8cfc13a",
    "created_by_name": "admin"
}

@AbhineetJain AbhineetJain requested a review from a team as a code owner July 15, 2022 00:59

ALTER TABLE ONLY template_versions ALTER COLUMN created_by SET NOT NULL;

COMMIT;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dwahler I am hoping wrapping it in BEGIN-COMMIT would help to fix the problem caused by the migration. Not really sure if this broke the server though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly, make gen is failing with:

panic: reached retry deadline
goroutine 1 [running]:
main.main()
	/home/runner/work/coder/coder/coderd/database/dump/main.go:19 +0x80c
exit status 2
make: *** [Makefile:60: coderd/database/dump.sql] Error 1

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed the bug, the scoping logic was not good.

@AbhineetJain AbhineetJain changed the title Abhineetjain/2876 add template version creator feat: add template version creator Jul 15, 2022
@AbhineetJain AbhineetJain force-pushed the abhineetjain/2876-add-template-version-creator branch from 48b232d to c98f87b Compare July 15, 2022 01:07
@AbhineetJain AbhineetJain mentioned this pull request Jul 15, 2022
4 tasks
Copy link
Contributor

@presleyp presleyp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Frontend ✅

@dwahler
Copy link
Contributor

dwahler commented Jul 15, 2022

While @AbhineetJain and I were discussing this, we realized that the migration failure is probably being caused by the temporary template versions that are created by the client, in preparation for creating a new template. Those rows have template_id set to null (since the actual template hasn't been created yet), so we don't have any way of knowing which user created them.

So the simplest fix is to just make template_versions.created_by also nullable.

@AbhineetJain AbhineetJain requested a review from dwahler July 15, 2022 20:18
Copy link
Contributor

@dwahler dwahler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@AbhineetJain AbhineetJain merged commit d04ba2c into main Jul 15, 2022
@AbhineetJain AbhineetJain deleted the abhineetjain/2876-add-template-version-creator branch July 15, 2022 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants