Skip to content
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

How can I access and verify the DB schema? #151

Closed
ghost opened this issue May 24, 2018 · 22 comments
Closed

How can I access and verify the DB schema? #151

ghost opened this issue May 24, 2018 · 22 comments

Comments

@ghost
Copy link

ghost commented May 24, 2018

Hello I am a beginner programmer.
I tried many times to check the DB schema structure while looking at the code through the project, but it continued to fail because of insufficient knowledge.
Can you teach me how to check and access the schema structure of a DB in Windows local environment?

@virusdefender
Copy link
Contributor

docker exec -it oj-postgres psql -U onlinejudge

\d+ to show tables

\d+ contest to show table details

@ghost
Copy link
Author

ghost commented May 29, 2018

I did not know my post was closed. Thanks for the good info.

@virusdefender
Copy link
Contributor

If you still have some questions, be free to reply in this issue

@ghost
Copy link
Author

ghost commented May 31, 2018

Hello.
We were able to solve the problem in the way you told us earlier. I want to draw up an ERD diagram to understand the structure of the table I have checked, but is there any way to check the ERD diagram right away using the current DB? If you have, I'd like to know how.

@zhblue
Copy link

zhblue commented May 31, 2018

there is a tool from sybase called powerdesigner
“Database”->"Update Model from Database"->“Database Reverse Engineering Options”
or check this link out
https://dbmstools.com/database-er-diagram-tools/postgresql

@ghost
Copy link
Author

ghost commented Jun 1, 2018

Thank you very much. I'll try the way you told me.

@ghost
Copy link
Author

ghost commented Jun 11, 2018

How are you? I did not solve the answer to the previous ERD diagram.
So now I've decided to figure out the flow of the priority submission code.

The following are some of the code we've identified.

[src / pages / oj / views / problem / problem.vue]

<script>

submitCode () {
        if (this.code.trim() === '') {
          this.$error('Code can not be empty')
          return
        }

        this.submissionId = ''
        this.result = {result: 9}
        this.submitting = true

        let data = {
          problem_id: this.problem.id,
          language: this.language,
          code: this.code,
          contest_id: this.contestID
        }
        if (this.captchaRequired) {
          data.captcha = this.captchaCode
        }
        const submitFunc = (data, detailsVisible) => {
          this.statusVisible = true
          api.submitCode(data).then(res => {
            this.submissionId = res.data.data && res.data.data.submission_id
            this.submitting = false
            this.submissionExists = true
            if (!detailsVisible) {
              this.$Modal.success({
                title: 'Success',
                content: 'Submit code successfully'
              })
              return
            }
            this.checkSubmissionStatus()
          }, res => {
            this.getCaptchaSrc()
            if (res.data.data.startsWith('Captcha is required')) {
              this.captchaRequired = true
            }
            this.submitting = false
            this.statusVisible = false
          })
        }

        if (this.contestRuleType === 'OI' && !this.OIContestRealTimePermission) {
          if (this.submissionExists) {
            this.$Modal.confirm({
              title: '',
              content: '<h3>You have submission in this problem, sure to cover it?<h3>',
              onOk: () => {
                setTimeout(() => {
                  submitFunc(data, false)
                }, 1000)
              },
              onCancel: () => {
                this.submitting = false
              }
            })
          } else {
            submitFunc(data, false)
          }
        } else {
          submitFunc(data, true)
        }
      }

</script>

A sequence diagram created through the code.

diagram

I additionally
How the submitted code information is stored in the DB,
I want to know how to communicate with the back-end, but I have not been able to do it yet.

I want to know the location of the code that requests the query to the DB

@virusdefender
Copy link
Contributor

@virusdefender
Copy link
Contributor

And you can use Pycharm to generate the graph

11111

@ghost
Copy link
Author

ghost commented Jun 12, 2018

Thank you very much. We will check the link you provided and we will study hard. I will also try using the method you have mentioned (Pycharm).

@ghost
Copy link
Author

ghost commented Jun 12, 2018

Fixed issue with DB query passing.
I've been wandering in the front-end .........(T^T)

@ghost
Copy link
Author

ghost commented Jun 14, 2018

I am sorry to have asked you a similar question.
How do I request an API from OnlineJudgeFE to OnlineJudge as shown below?
I'm wondering where that code is.

onlinejudge

@virusdefender
Copy link
Contributor

ajax request

@zhblue
Copy link

zhblue commented Jun 14, 2018

by http request, i guess

@ghost
Copy link
Author

ghost commented Jun 14, 2018

I expected it to be ajax. However, I did not know how the ajax works. I am grateful to know for sure by the answer.

@zhblue
Copy link

zhblue commented Jun 14, 2018

if you use chrome, try press F12 , switch to network tab, check on "Preserve log" , then watch the log while operating the web UI.

@ghost
Copy link
Author

ghost commented Jun 29, 2018

Hello I apologize that I have relied on the answer to the question before I have solved it myself.

Since then, I have been working on my own for a long time to understand the meaning of each function and solve the problem.
cap

I think we need to learn more to handle the project. However, I am more interested in modifying the site and decided to do something new.

If you click 'submission', you can check the detailed result in 'Status' after compiling through various functions.

And I thought. I added the 'Run' button and thought about the function to skip the save in DB and check the compiled result in the 'problem'.

Result screen in [Status]

test2

Result screen in [Problem](but, Load the value stored in DB)

test

I understand the flow, but I have not been able to grasp the details yet. If you tell only the code part that stores the input values ​​in the DB (submission table), you will be able to execute the idea. I'm sorry to ask you this again.

@virusdefender
Copy link
Contributor

virusdefender commented Jun 29, 2018

the most simple way is to change this line

https://github.com/QingdaoU/OnlineJudge/blob/master/judge/dispatcher.py#L149

and then you can get the output from the database

WARNING: database size may increase significantly

PS: you can search virusdefender in telegram

@ghost
Copy link
Author

ghost commented Jun 29, 2018

thank you. However, in order to prevent the DB usage from increasing, the link is predicted to store data in line 176 'submission.save ()' (DB of the given code) I am looking for a way not to use this.
And is submission.save () a command to save in DB?

@zhblue
Copy link

zhblue commented Jun 29, 2018

maybe just delete it by ajax after showed once in browser

@ghost
Copy link
Author

ghost commented Jul 3, 2018

Thanks zhblue
But I need to output the compiled result using a method that is not stored in Postgres.
I expect to save the input data in Submission declared in Models.py and then save the result to Postgres, but I can not find the location

@zhblue
Copy link

zhblue commented Jul 5, 2018

maybe add a new table to the db, like here what i did in another system.
https://github.com/zhblue/hustoj/blob/master/trunk/install/db.sql#L194

CREATE TABLE  `custominput` (
  `solution_id` int(11) NOT NULL DEFAULT 0,
  `input_text` text,
  PRIMARY KEY (`solution_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

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

No branches or pull requests

2 participants